4

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.

3 Answers 3

4

"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

Sign up to request clarification or add additional context in comments.

2 Comments

That doesn't work. From what I can tell, that just prefixes the map state output with mapOutput. The output I'm getting from the map state is the Attempts array which contains a bunch of metadata about each iteration
so, entire array of Attempts will be going out as mapOutput.Attempts and step three input will be combined input and output of step two? the first block is the input of the step 3, Comment is input step function , inputForMap is input of step two, mapOutput is output of step three.
1

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

2 Comments

we will not be able to use out of step 2 at all with ResultPath: null , where as with ResultPath: someVariable (like my answer) will append the out of step 2 to someVariable , so, we have access to input as well as output of step 2, in step 3.
That's fair. In this case though, Step 2 doesn't produce any meaningful output, which is my question was how to make Step 1 output the input to Step 3, not combine them. I appreciate the answer though, it was educational.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.