在 AWS Step Function 的 Choice 步骤中,我们希望将 AWS Lambda 函数的结果与使用“NumericGreaterThan”作为参数给出的阈值进行比较。
在我们的示例中,我们将从 lambda 计算出的 a 与事件给定的阈值进行比较。
我尝试以下列方式定义我的步骤函数:
{
"StartAt": "Check Enough Data",
"States": {
"Check Enough Data": {
"Type": "Task",
"Resource": "arn:aws:lambda:REGION:ID:function:FUNCTION:$LATEST",
"Next": "Validate Count",
"ResultPath": "$.count"
},
"Validate Count": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.count",
"NumericGreaterThan": "$.threshold",
"Next": "Succeed State"
}
],
"Default": "Wait 24 Hours"
},
"Wait 24 Hours": {
"Type": "Wait",
"Seconds": 86400,
"Next": "Check Enough Data"
},
"Succeed State": {
"Type": "Succeed"
}
}
}
但得到一个错误类型的预期值:整数,字符串的浮点数。
如果我用硬编码值(如 20)替换“$.threshold”,它可以工作,但该值不是我想要的动态值。
以下输入应导致 lambda 进入成功状态:
{
"country": "japan",
"threshold": 40
}
我知道我们可以用另一个 Lambda 函数替换 Choice 步骤,但我们不想从成本效益问题上这样做。
有没有人知道如何解决这个问题?
最佳答案
您可以根据文档使用“NumericGreaterThanPath”运算符 https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-choice-state.html
在选择规则中,通过将“路径”附加到支持的比较运算符的名称,可以将 Variable 的值与来自状态输入的另一个值进行比较。
NumericEqualsPath、NumericGreaterThanPath、NumericGreaterThanEqualsPath 等。
关于amazon-web-services - AWS Step Function NumericGreaterThan 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58750863/