- Newest
- Most votes
- Most comments
The information provided by the re:Post Agent is generally correct but needs more technical precision regarding the field names and permissions.
To pass tags to an ECS task from a Step Function, you must use the Parameters field (not "Arguments") in your Task state definition. Since Step Functions integrates directly with the ECS RunTask API, you can include a Tags array as follows:
"Parameters": { "Cluster": "your-cluster-arn", "TaskDefinition": "your-task-def-arn", "Tags": [ { "Key": "Environment", "Value": "Production" }, { "Key": "Project", "Value.$": "$.projectName" } ], ... }
Two critical things to remember:
-
IAM Permissions: The Step Functions execution role must have the ecs:TagResource permission in addition to ecs:RunTask. Without this, the task will fail to launch with an "Access Denied" error.
-
Tag Propagation: If you want to automatically inherit tags from the Task Definition, you can also add "PropagateTags": "TASK_DEFINITION" to the parameters.
For dynamic tagging, you can use the .$ suffix (as shown above) to pull tag values from your state input.
When orchestrating ECS tasks with Step Functions state machines, you can pass tags to tasks through the Arguments section of your Task state definition. While the sources don't provide a specific example of passing tags, the integration allows you to use the Overrides parameter to customize task execution.
In your state machine definition, you would structure your Task state to call the ECS RunTask API action. Within the Arguments field, you can specify task parameters including container overrides, launch type, cluster, and task definition. To pass tags, you would include a Tags parameter in your Arguments section following the ECS RunTask API structure.
The Step Functions integration with ECS supports passing various parameters to customize task execution, including environment variables through ContainerOverrides. You can use similar patterns to include tags by adding them to the task configuration within your state machine definition. The tags would be specified as key-value pairs in the format expected by the ECS RunTask API.
Keep in mind that when configuring your state machine to run ECS tasks, you'll need appropriate IAM permissions. Step Functions generates IAM policies based on the resources in your state machine definition, and these policies must allow the necessary ECS actions including running and describing tasks.
Sources
Run Amazon ECS or Fargate tasks with Step Functions - AWS Step Functions
Relevant content
- asked 15 days ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
