I have the following state defined in my state machine.
"loop":{
"Type": "Pass",
"Result":{
"totalCount": "$.newFieldsResponse.body.count",
"currentCount": 0,
"step": 1
},
"ResultPath": "$.iteration",
"Next":"iterateLoop"
},
I expect the output of the state to be:
"newFieldsResponse": {
"isSuccess": true,
"error": "",
"body": {
"count": 2,
"fields": [...]
}
},
"iteration": {
"totalCount": 5,
"currentCount": 0,
"step": 1
}
}
iteration property is added to the input with totalCount property to be set to count of items in fields array.
However, the output for "iteration" property is set as:
"iteration": {
"totalCount": "$.newFieldsResponse.body.count",
"currentCount": 0,
"step": 1
}
It looks like the value "$.newFieldsResponse.body.count" is not getting resolved and is output as is.
Is there something I am doing wrong ? Can someone please advice on how to make it work ?
Step Functions paths use JsonPath syntax. To specify that a parameter use a path to reference a JSON node in the input, end the parameter name with . $ . For example, if you have text in your state input in a node named message , you could pass that to a parameter by referencing the input JSON with a path.
Step Functions is based on state machines and tasks. A state machine is a workflow. A task is a state in a workflow that represents a single unit of work that another AWS service performs. Each step in a workflow is a state.
In the console, go to the “Step Functions” section (under Application Services). Choose “Create a State Machine”. Once you have pasted in the code, you will need to add the ARN (resource locators) for your two lambda functions.
The Map state ( "Type": "Map" ) can be used to run a set of steps for each element of an input array. While the Parallel state executes multiple branches of steps using the same input, a Map state will execute the same steps for multiple entries of an array in the state input.
It works in a combination of two of the solutions here exposed:
{
"loop": {
"Type": "Pass",
"parameters": {
"totalCount.$": "$.newFieldsResponse.body.count",
"currentCount": 0,
"step": 1
},
"ResultPath": "$.iteration",
"Next": "iterateLoop"
}
}
This is possible through "Parameters" in pass state
JSON
{
"loop": {
"Type": "Pass",
"Parameters": {
"totalCount": "$.newFieldsResponse.body.count",
"currentCount": 0,
"step": 1
},
"ResultPath": "$.iteration",
"Next": "iterateLoop"
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With