Search code examples
jsonamazon-web-servicesaws-step-functions

AWS Map State Input Management


I'm currently making some tests using AWS step functions, despite its ease of use I am not able to correctly manage the input of the map state:

My test state machine

Here is the input provided:

{
"keep": "elementToKeep",
  "my_array": [
    "element0",
    "element1",
    "element2"
  ]
}

I' like to make the map state iterate over my_array such that the inner state recives as input

  • { "keep": "elementToKeep", "element": "element0" } at the 1st iteration
  • { "keep": "elementToKeep", "element": "element1" } at the 2nd iteration
  • and so on ...

Right now I am only able to provide "element0" (at the 1st interaction) as input, not even being able to correctly format it with JSONSyntax.

Below I paste the State Machine JSON structure. I am more familiar with the workflow view, but any help is highly appreciated.

{
  "StartAt": "Map",
  "States": {
    "Map": {
      "Type": "Map",
      "End": true,
      "Iterator": {
        "StartAt": "Pass",
        "States": {
          "Pass": {
            "Type": "Pass",
            "End": true
          }
        }
      },
      "ItemsPath": "$.my_array"
    }
  }
}

Solution

  • After a few hours of digging I found the solution:
    For some reason the item of the array provided as input to the inner function (here element0, element1, etc...) is mapped as $$.Map.Item.Value (for some reasons).
    So if it's necessary to provide other parameters beside the array element, in the "Transform array items" field is sufficient to place:

    {
      "element.$": "$$.Map.Item.Value",
      "keep.$": "$.keep"
    }
    

    Which produced the input desired as specified in the question, thus I'll mark the question as closed.

    In this link it's possible to find the source for this answer.