我在AWS Step Function中有一个Choice状态,它将比较Input的数组长度并决定下一个状态.
但是,获取数组长度的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": []
}
]
}
所以我试图获取元数据中项目的长度[2]并在值大于0时进行比较.
我试图在此website中验证JsonPath $.Metadata [2] .Items.length()并返回0.
我不确定我是否错过了什么.我在AWS Step Function的文档或示例中找不到有关在jsonpath中使用函数的任何信息.
我将不胜感激任何帮助.谢谢!
最佳答案 步骤函数不允许您使用函数来获取值.从
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"
}
]
},