- Newest
- Most votes
- Most comments
When working with Amazon ECS, you can retrieve tags for stopped tasks, including their containers, using the task metadata endpoint or AWS CLI commands.
For retrieving tags of stopped tasks and their containers, you can use the AWS CLI with the describe-tasks command. First, list the stopped tasks in your cluster:
aws ecs list-tasks \
--cluster cluster_name \
--desired-status STOPPED \
--region region
Then, describe the specific stopped task to get detailed information:
aws ecs describe-tasks \
--cluster cluster_name \
--tasks task_ARN \
--region region
This will provide you with information about the stopped task, including the stop code, stopped reason, and container details.
For more comprehensive tag information, you can use the task metadata endpoint. The task metadata endpoint version 4 provides a specific path for retrieving task and container instance tags:
${ECS_CONTAINER_METADATA_URI_V4}/taskWithTags
This endpoint returns metadata for the task along with the task and container instance tags that can be retrieved using the ListTagsForResource API. The response includes task tags in the TaskTags field and container instance tags in the ContainerInstanceTags field.
Similarly, in task metadata endpoint version 2, you can use:
169.254.170.2/v2/metadata/taskWithTags
It's important to note that these metadata endpoints are accessible from within the container itself while it's running, so they wouldn't be directly accessible for already stopped containers. For stopped containers, the AWS CLI approach using describe-tasks is the recommended method to retrieve the available information.
Sources
Amazon ECS task metadata endpoint version 4 - Amazon Elastic Container Service
Amazon ECS task metadata v4 examples - Amazon Elastic Container Service
Amazon ECS task metadata endpoint version 2 - Amazon Elastic Container Service
Viewing Amazon ECS stopped task errors - Amazon Elastic Container Service
Relevant content
asked 2 years ago
asked 3 years ago
asked a year ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 2 months ago
