Search code examples
amazon-web-servicesspring-bootdockeramazon-ecsaws-fargate

How can I get the Docker ID from an AWS-Task and log it into a SpringBoot app?


I own an AWS task that runs on ECS Fargate. Now I would like to have the task ID printed in the SpringBoot app.

I already read in some places that I have to set the environment variable ECS_ENABLE_CONTAINER_METADATA = true to have access to it inside the container. My question is now, do I have to set this environment variable when creating the ECS cluster or the ECS service with the Task.

And after I have done that, how can I access this ID in the app. Does the AWS-SDk already offer helpful operations?


Solution

  • Hey Lucas to get the task id programmatically you have to make a request to the agents metadata endpoint

    curl http://localhost:51678/v1/metadata