AWS Step Function - Adding dynamic value to Pass state type
I too got stuck on this before I figured it out.
Pass states can be used, but @ankitkanojia and @shashi 's answers need a minor modification.
If you want to use input paths, the keys inside parameters need to end in ".$" ("totalCount.$")
So the state specification should be as follows:
"loop":{
"Type": "Pass",
"Result":{
"totalCount.$": "$.newFieldsResponse.body.count",
"currentCount": 0,
"step": 1
},
"ResultPath": "$.iteration",
"Next":"iterateLoop"
},
It works in a combination of two of the solutions here exposed:
- Add Parameter in Pass step
- Add *.$ in the name of the var you want to pass:
{
"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"
}
}
Looks like this may not be possible. The workaround I did is to use "Parameters" property. From AWS documentation: "For key-value pairs where the value is selected using a path, the key name must end in *.$. ".
So resolved the above by :
- Changing Pass state to remove any dynamic value reference
"loop":{
"Type": "Pass",
"Result":{
"currentCount": 0,
"step": 1
},
"ResultPath": "$.iteration",
"Next":"iterateLoop"
},
- creating a Parameters property where I need the values as below:
"iterateLoop":{
"Type":"Task",
"Resource": "arn:aws:lambda:....r",
"Parameters":{
"totalCount.$": "$.newFieldsResponse.body.count",
"currentCount.$": "$.iteration.currentCount",
"step.$": "$.iteration.step"
},
"ResultPath": "$.iteration",
"Next":"continueLoop"
},
totalCount, currentCount and step all read the value from using a path in the state input. The key needs to be appended with a ".$" at the end.