问题
I have a Choice state in AWS Step Function that would compare an array's length from Input and make decision to go next state.
However, the length()
function, to get the array's length, returned an error:
{
"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."}
The Choice state's definition is as below:
"CheckItemsCountState":{
"Type": "Choice",
"InputPath": "$",
"OutputPath": "$",
"Default": "NoItemsState",
"Choices":[
{
"Variable": "$.Metadata[2].Items.length()",
"NumericGreaterThan": 0,
"Next": "ProcessState"
}
]
},
The state is connected some other state that returns a JSON. The JSON is as below:
{
"Metadata": [
{
"foo": "name"
},
{
"Status": "COMPLETED"
},
{
"Items": []
}
]
}
So I was trying to get the length of Items
in Metadata[2]
and make comparison if the value is greater than 0.
I have tried to validate the JsonPath $.Metadata[2].Items.length()
in this website and it returns 0.
I am not sure if I've missed anything. I couldn't find any information in AWS Step Function's docs or example on using function in jsonpath.
I would appreciate for any help. Thank you!
回答1:
Step Functions do not allow you to use functions to get values. From the Choice Rules documentation:
For each of these operators, the corresponding value must be of the appropriate type: string, number, Boolean, or timestamp.
To do what you're asking, you would need to get the array length in the previous function and return it as part of the output.
{
"Metadata": [
{
"foo": "name"
},
{
"Status": "COMPLETED"
},
{
"Items": [],
"ItemsCount": 0
}
]
}
Then in the Step Function Choice step:
"CheckItemsCountState":{
"Type": "Choice",
"InputPath": "$",
"OutputPath": "$",
"Default": "NoItemsState",
"Choices":[
{
"Variable": "$.Metadata[2].ItemsCount",
"NumericGreaterThan": 0,
"Next": "ProcessState"
}
]
},
来源:https://stackoverflow.com/questions/45341395/aws-step-function-function-length-returned-error-in-variable-field-in-choice