0 votes
1 view
in AWS by (19.2k points)

Amazon recently added the wonderful feature of tagging EC2 instances with key-value pairs to make the management of large numbers of VMs a bit easier.

Is there some way to query these tags in the same way as some of the other user-set data? For example:

$ curl http://169.254.169.254/latest/meta-data/placement/availability-zone

us-east-1d

Is there some similar way to query the tags?

1 Answer

0 votes
by (44.6k points)

To retrieve your instance id use a combination of AWS metadata tool and the new Tag API to retrieve the tags for the instance.

After you have installed ec2-metadata and ec2-describe-tags, use this example shell command to retrieve your current instances name. In this example, “Name=demo” is the tag you have to use.

Assumes EC2_PRIVATE_KEY and EC2_CERT environment variables are set.

ec2-describe-tags \

   --filter "resource-type=instance" \

   --filter "resource-id=$(ec2-metadata -i | cut -d ' ' -f2)" \

   --filter "key=Name" | cut -f5

This returns demo.

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
asked Sep 28, 2019 in AWS by chandra (29.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...