How to assign a unique ID to each instance of a task in Amazon ECS?

0

I want to uniquely identify each instance of a task that is backing an ECS service, I'm using EC2 launch type - but it'd be good to find an answer that works for Fargate too.

I found this StackOverflow question from over 18 months ago. It has no answers, but a few people have posted (deleted) "answers" asking if there's been any solution found.

https://stackoverflow.com/questions/69406093/how-to-assign-a-unique-id-to-each-instance-of-a-task-in-amazon-ecs

Does anyone here know if there's a way to do this?

  • can you elaborate the use case a bit ? Why you want to assign unique ID to each instance of a task ?

Shorn
asked a year ago1166 views
3 Answers
1

Every task gets an unique ARN at the time of launch that can be retrieved from the ECS API or from the ECS metadata endpoint inside the container at the url: ${ECS_CONTAINER_METADATA_URI_V4}/task. At that endpoint look for TaskARN. More information on the ECS Metadata endpoint and all the available parameters can be found in the documentation.

profile pictureAWS
EXPERT
Toni_S
answered a year ago
0

https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerInstance.html if you are referencing an id for each instance, it is this: ec2InstanceId, because what you are seeing in the metadata you presented is the id of the container within this deployed instance, not the instance.

I am just answered the question https://stackoverflow.com/a/76040299/4843573

answered a year ago
  • No - multiple containers can be running on the same instance, container-instance is not a unique identifier.

0

A unique ID is already assinged to each instance of a Task. Look at tasks in the console or use the CLi..

Execute

aws ecs  list-tasks --cluster  [clustername]

to see all the unqiue tasks

profile picture
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions