1

In AWS step function, i need to run a for loop. Pass the particular element of for loop + some common information for all elements of loop.im getting the common information through input. But the problem is when I try to set parameter as $.something,it only shows the particular element of the loop as input..doesn't show the parent input.

1 Answers1

0

This is a example.

{
  "StartAt": "Setup Variables",
  "States": {
    "Setup Variables": {
      "Type": "Pass",
      "Parameters": {
        "JobInfo": {
          "Id.$": "$$.Execution.Name",
          "Name.$": "$$.StateMachine.Name"
        },
        "DataList": [
          1,
          2,
          3
        ]
      },
      "Next": "Iterate Data"
    },
    "Iterate Data": {
      "Type": "Map",
      "InputPath": "$",
      "ItemsPath": "$.DataList",
      "ItemSelector": {
        "data.$": "$$.Map.Item.Value",
        "JobInfo.$": "$.JobInfo"
      },
      "ItemProcessor": {
        "StartAt": "Process data",
        "States": {
          "Process data": {
            "Comment": "Step the process the data",
            "Type": "Pass",
            "End": true
          }
        },
        "ProcessorConfig": {
          "Mode": "DISTRIBUTED",
          "ExecutionType": "STANDARD"
        }
      },
      "MaxConcurrency": 1000,
      "End": true
    }
  }
}

Here I want to process the DataList parallaly using a map, But I need to use the JobInfo object in each parallel step,

You need to understand InputPath, ItemsPath, ItemSelector in Map, Since InputPath is "$" I can access all the data from the Map state, But the data that going to iterate can be set from ItemsPath. Since it is "$.DataList", It will iterate through DataList, But I also need my JobInfo object as well while iterating, So we can update this iterate object again using ItemSelector.

"data.$": "$$.Map.Item.Value"

"$$.Map.Item.Value" means the original item value(a item from DataList). It is set again as data. and the job info taken from the input. That's all.

You can refere below link to get more understanding.

https://states-language.net/spec.html

Chandika
  • 93
  • 1
  • 8