0

I have the following definition. I want to be able to pass the current iteration number of the map to my ecs task like this python src.py --my_argument <index>. I used "$$.Map.Item.Index" but it doesn't work. I just runs it literally like this: python src.py --my_argument $$.Map.Item.Index

{
  "Comment": "A state machine that iterates over an array and creates an ECS task for each item.",
  "StartAt": "IterateArray",
  "States": {
    "IterateArray": {
      "Type": "Map",
      "InputPath": "$.arrayField", 
      "ItemsPath": "$", 
      "MaxConcurrency": 0,
      "Iterator": {
        "StartAt": "RunECSTask",
        "States": {
          "RunECSTask": {
            "Type": "Task",
            "Resource": "arn:aws:states:::ecs:runTask.sync",
            "Parameters": {
              "LaunchType": "FARGATE",
              "Cluster": "ClusterName",
              "TaskDefinition": "TaskDefinitionName",
              "Overrides": {
                "ContainerOverrides": [
                  {
                    "Name": "yourContainerName",
                    "Command": [
                      "python",
                      "src.py",
                      "--my_argument",
                      "$$.Map.Item.Index"
                    ]
                  }
                ]
              }

            },
            "End": true
          }
        }
      },
      "End": true
    }
  }
}

1 Answer 1

0

Replace "Command" with "Command.$". Appending .$ to a key tells Step Functions to interpolate the path references in the value.

See Passing Data to an Amazon ECS Task in the docs for more examples.

Sign up to request clarification or add additional context in comments.

2 Comments

that didn't work for me because I think it was trying to pass the entire content instead of the value of the current iteration so I had to try something else. Can you pls take a look at my follow up question though?: stackoverflow.com/questions/77992087/…
@jamespow OP: "I want to be able to pass the current iteration number".

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.