LucaBonadia
LucaBonadia

Reputation: 91

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

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

Upvotes: 1

Views: 1848

Answers (2)

Xixi
Xixi

Reputation: 96

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

Upvotes: 1

LucaBonadia
LucaBonadia

Reputation: 91

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.

Upvotes: 0

Related Questions