Is there a way for an ECS Task to be able to fetch the EC2 metadata of where it is deployed?
From AWS documentation of ec2 instance metadata, I can retrieve the EC2 instance metada when I am inside the ec2 instance itself. I'm more interested in fetching the instance-id and can be achieved with command
curl http://169.254.169.254/latest/meta-data/instance-id
This is achieved only when I will go directly to the ec2 instance and execute the query/command, but how will this be possible if I want to fetch the ec2 metadata when I'm from an ECS task running on the EC2 instance? Based on AWS documentation of task metadata, I only managed to fetch the details of the ECS task itself but can't manage to fetch the ec2 metadata where the task is running.
Is this possible?
The setup:
- ec2 instance is in an ecs cluster
- ecs task is deployed randomly on any ec2 instance inside the cluster