1

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

2 Answers 2

1

I wasn't able to find what "Transform array items" field is (maybe the name changed), so I ended up on another question with a more detailed answer. I paste it here in case it is useful for others: Pass multiple inputs into Map State in AWS Step Function

"ItemsPath": "$.my_array",
"Parameters": {
  "element.$": "$$.Map.Item.Value",
  "keep.$": "$.keep"
}
0

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.

1
  • sorry can you paste what your full state machine json looked like afterwards?
    – james pow
    Commented Feb 12 at 6:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.