I need to get the value for a particular tag in Python within an EC2 instance.
Restriction: Can’t use the Python EC2 metadata module as “Tags allowed in metadata” won’t be enabled.
So I cannot do “ec2_metadata.tags[“Name”]” as that would throw an 404 error.
What other way can we do this? The curl method wouldn’t work either since that also requires the metadata tags to be enabled.
2
Answers
My solution:
Then I get the value for a particular tag by:
I’m sure there are other solutions but since I had to implement any solution for now, this is it.
Get the instance ID from
http://169.254.169.254/latest/meta-data/instance-id
, then use thedescribe_instances
API with the instance id.