Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing common parameters in map in Step function

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.

like image 787
S. D. chowdhury Avatar asked Aug 23 '26 14:08

S. D. chowdhury


1 Answers

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

like image 72
Chandika Avatar answered Aug 25 '26 11:08

Chandika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!