Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Step Functions - Use output from older step in later step (non-sequential)

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.

like image 961
J_Stan Avatar asked Nov 01 '25 18:11

J_Stan


2 Answers

"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
      }
   }
}

enter image description here

Step three Input: enter image description here

like image 78
Balu Vyamajala Avatar answered Nov 04 '25 06:11

Balu Vyamajala


I found out, all I needed to do was set ResultPath: null on Step 2, and it would pass the input straight through

like image 24
J_Stan Avatar answered Nov 04 '25 07:11

J_Stan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!