How to identify whether my container is running on AWS ECS or not?

Viewed 4803

If I am running my docker based container in AWS ECS (EC2 Container Service), is there a way I can identify from inside the application whether my container is running on AWS ECS or not? This is required, because my docker container can run on any platform, but when it is running on AWS ECS, I need to perform some extra operations.

3 Answers

I've tried other alternatives that were posted before this response, but all of them did not work for ECS. I don't know if it has changed but now, if you want to verify if the container is running on ECS, you should call: http://169.254.170.2/v2/metadata/

More info: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-metadata-endpoint-v2.html

And if you want to verify if the container is running on EC2, you should call: http://169.254.169.254/latest/meta-data/

More info: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html

Related