Monday, October 29, 2012

AWS EC2 Instance Metadata

There is an easy way to access to Instance information from within. This is very useful when writing scripts who are executed inside the Instance. The method is accessing the Instance Metadata using a HTTP GET call to the IP It works on any EC2 instance and the IP address is always the same.


- Obtaining the Instance ID:

$ wget -q -O -

- Public Hostname:

$ wget -q -O -

- Public IPv4 Address:

$ wget -q -O -

Check the Instance Metadata manual page for further reference. 

Unfortunately, the Instance Tags are not available through Metadata yet (forums). There is a workaround using the API ec2-describe-instances command. 

Example: To obtain a whole Tag list from the instance we are running in:

$ ec2-describe-instances `wget -q -O -` --show-empty-fields | grep TAG

TAG instance i-87eef4e2 Another Tag Another Value
TAG instance i-87eef4e2 Name mymachine1

No comments:

Post a Comment