gpt4 book ai didi

node.js - AWS Step Function : Function . length() 在选择状态的变量字段中返回错误

转载 作者:搜寻专家 更新时间:2023-10-31 22:49:21 25 4
gpt4 key购买 nike

我在 AWS Step Function 中有一个 Choice 状态,它会比较输入的数组长度并决定进入下一个状态。

但是,length() 函数在获取数组长度时返回错误:

{
"error": "States.Runtime",
"cause": "An error occurred while executing the state 'CheckItemsCountState' (entered at the event id #18). Invalid path '$.Metadata[2].Items.length()': The choice state's condition path references an invalid value."

}

Choice状态的定义如下:

     "CheckItemsCountState":{  
"Type": "Choice",
"InputPath": "$",
"OutputPath": "$",
"Default": "NoItemsState",
"Choices":[
{
"Variable": "$.Metadata[2].Items.length()",
"NumericGreaterThan": 0,
"Next": "ProcessState"
}
]
},

状态连接到返回 JSON 的其他状态。 JSON如下:

{
"Metadata": [
{
"foo": "name"
},
{
"Status": "COMPLETED"
},
{
"Items": []
}
]
}

所以我试图在 Metadata[2] 中获取 Items 的长度,如果该值大于 0 则进行比较。

我已尝试验证此 website 中的 JsonPath $.Metadata[2].Items.length()并返回 0。

我不确定我是否遗漏了什么。我在 AWS Step Function 的文档或示例中找不到有关在 jsonpath 中使用函数的任何信息。

如有任何帮助,我将不胜感激。谢谢!

最佳答案

Step Functions 不允许您使用函数来获取值。来自Choice Rules documentation :

For each of these operators, the corresponding value must be of the appropriate type: string, number, Boolean, or timestamp.

要执行您要求的操作,您需要在上一个函数中获取数组长度并将其作为输出的一部分返回。

{
"Metadata": [
{
"foo": "name"
},
{
"Status": "COMPLETED"
},
{
"Items": [],
"ItemsCount": 0
}
]
}

然后在Step Function Choice步骤:

"CheckItemsCountState":{  
"Type": "Choice",
"InputPath": "$",
"OutputPath": "$",
"Default": "NoItemsState",
"Choices":[
{
"Variable": "$.Metadata[2].ItemsCount",
"NumericGreaterThan": 0,
"Next": "ProcessState"
}
]
},

关于node.js - AWS Step Function : Function . length() 在选择状态的变量字段中返回错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45341395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com