From a regular ECS container running with the bridge mode, or from a standard EC2 instance, I usually run
curl http://169.254.169.254/latest/meta-data/local-ipv4
to retrieve my IP.
In an ECS container running with the awsvpc network mode, I get the IP of the underlying EC2 instance which is not what I want. I want the address of the ENI attached to my container. How do I do that?
A new convenience environment variable is injected by the AWS container agent into every container in AWS ECS:
${ECS_CONTAINER_METADATA_URI}This contains the URL to the metadata endpoint, so now you can do
The output looks something like
Under the key
Networksyou'll findIPv4AddressYou application code can then look something like this (python)