如何比较两个输入字符串值(实际上是 AWS Step 函数中的数值)

问题描述 投票:0回答:1

我想比较两个输入值,这实际上是一个数字,但由于它从 lambda 函数输出另一个状态机步骤,因此它转换为字符串值,我想将它们比较为大于或等于的数字,然后继续处理其他值状态机步进或终止它,但似乎无法比较它们并且总是走错误的步骤。

我已经按照链接中的建议尝试了

States.FormatNumber
States.StringToJson
Step函数将字符串转换为数字但它不起作用。有没有什么办法可以不用去lambda函数去比较呢?

例如:我的输入如下:

{
   "v2_table": {
      "count": "2"
   },
   "original_table": {
     "count": "2"
   }
}

AWS Step 功能如下:

{
  "StartAt": "CompareCounts",
  "States": {
    "CompareCounts": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.v2_table.count",
          "NumericGreaterThanEqualsPath": "$.original_table.count",
          "Next": "CountsMatch"
        }
      ],
      "Default": "CountsDoNotMatch"
    },
    "CountsMatch": {
      "Type": "Pass",
      "End": true
    },
    "CountsDoNotMatch": {
      "Type": "Pass",
      "End": true
    }
  }
}

对于上面的输入,它会转到

CountsDoNotMatch
,这是完全错误的。

使用上述输入执行结果如下

amazon-web-services aws-step-functions
1个回答
0
投票

在“选择”状态下,应使用

StringGreaterThanEqualsPath
,因为变量是字符串。

完整状态机:

{
  "StartAt": "CompareCounts",
  "States": {
    "CompareCounts": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.v2_table.count",
          "StringGreaterThanEqualsPath": "$.original_table.count",
          "Next": "CountsMatch"
        }
      ],
      "Default": "CountsDoNotMatch"
    },
    "CountsMatch": {
      "Type": "Pass",
      "End": true
    },
    "CountsDoNotMatch": {
      "Type": "Pass",
      "End": true
    }
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.