简体   繁体   中英

AWS step functions map state: pass output from current iteration as input to next iteration

I have a map state that takes an array as input. I understand that the map will iterate over the elements of the array. However, what I want to do is pass the output of one iteration into the input of the next. Is this possible without writing to a DB or S3? I have tried endless combinations of InputPath, OutputPath, and ResultPath, but no matter what I do to try to modify the input of state 1 from state 0, it simply reads from the array, and it seems I can't modify the input array from within the map. Example template:

"Map":{
  "Type": "Map",
  "ItemsPath": "$.stages",
  "Parameters": {
    "stage.$": "$$.Map.Item",
  },
  "Iterator": {
    "StartAt": "StartStage",
    "States": {
      "StartStage":{
        "Type": "Task",
        "Resource":"arn:aws:states:::lambda:invoke.waitForTaskToken",
        "Parameters":{
          "FunctionName":"...",
          "Payload":{
            "myArgs.$": "$.stage.Value",
          }
        },
        "End": true
      }
    }
  },
  "MaxConcurrency": 1,
}

The other option is to create a while loop like this:

  1. Set a variable to track your index (pos = 0)
  2. All the states that you want to iterate
  3. Increase your index ( pos++)
  4. A choice state: If your index is less that your items count go to step1.

This way you have access to the result of previous iteration. But processing and merging the result of iteration is not happening automatically and you need to add a state to do it for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM