Reputation: 503
In a state machine with 3 steps, is it possible for step 3 to use the output of step 1? In my specific scenario I have:
Task -> Map State -> Task
where I'm specifically interested in using the Map State's input for its first iteration as the input for Step 3. I could handle the entire input to the map state as well, but so far I'm not seeing how to achieve either of these.
Upvotes: 4
Views: 4079
Reputation: 715
If you want to discard the output, you need to use ResultPath: null
, this will maintain the original input without any change (You can check more details about the ResultPath here). Take in consideration that the default value for ResultPath
is $
, which means that the state will overwrite the entire context with the result of the step, that why you were losing all the previous context in your state machine.
Another solution, in case you need the result of the step 2 in your workflow, is to write the result in a new node, like Balu Vyamajala explained in his answer.
Upvotes: 1
Reputation: 503
I found out, all I needed to do was set ResultPath: null
on Step 2, and it would pass the input straight through
Upvotes: 1
Reputation: 10333
"ResultPath":"$.mapOutput"
will prefix mapOutput
to output of the map. and combined input and output will be send as input to following task.
This is input to Step 3:
{
"Comment": "Insert your JSON here",
"inputForMap": [
"iter 1",
"iter2"
],
"mapOutput": [
"iter 1",
"iter2"
]
}
Here is entire definition
{
"StartAt":"Dummy Step 1 Output",
"States":{
"Dummy Step 1 Output":{
"Type":"Pass",
"Result":[
"iter 1",
"iter2"
],
"ResultPath":"$.inputForMap",
"Next":"loop on map"
},
"loop on map":{
"Type":"Map",
"ResultPath":"$.mapOutput",
"Next":"Step three",
"Iterator":{
"StartAt":"Step 2 - Looping on map",
"States":{
"Step 2 - Looping on map":{
"Type":"Pass",
"End":true
}
}
},
"ItemsPath":"$.inputForMap",
"MaxConcurrency":1
},
"Step three":{
"Type":"Pass",
"Next":"End of Step Function"
},
"End of Step Function":{
"Type":"Pass",
"End":true
}
}
}
Upvotes: 4