From the running aws ecs instances, can I get the detail about its cluster name and container instance ID?
In EC2, I can run below curl command to get its instance id, do I have similar command in ECS?
curl http://169.254.169.254/latest/meta-data/instance-id
Answer my own question, in AWS ECS cluster, a daemon is running, you can queue its metadata by below commands
$ curl http://localhost:51678/v1/tasks | python -mjson.tool
$ curl -s http://localhost:51678/v1/metadata | python -mjson.tool
{
"Cluster": "application-1",
"ContainerInstanceArn": "arn:aws:ecs:us-east-2:1234567890:container-instance/ee4d3451d-2de3-4180-b1c6-023ed6e8c343",
"Version": "Amazon ECS Agent - v1.14.1 (467c3d7)"
}
This will be useful if you need to deregister itself from ECS cluster, for example, you use spot instance in ecs cluster.
Refer: