Finding information about an Amazon EC2 instance

One thing hit me when I was working with EC2 and I wanted to find some information about the instance itself. This did not seem to be readily available and I spent a frustrating 45 minutes trying to get what I was looking for. Eventually I found a very easy way to get the amazon instance information using CURL. Enter the following command appended by the Amazon information you are looking for:

$ curl http://169.254.169.254/1.0/meta-data/

This command can be appended with:
ami-id
ami-launch-index
ami-manifest-path
hostname
instance-id
local-ipv4
public-keys/
reservation-id
security-group
s

You can also pass data to the instance when you start it using EC2 tools  and retrieve the data within the instance using the above command. E.g if you started the instance using the command
ec2-run-instances ami-3abe5953 -d “Some data I need”

In the instance
$ curl http://169.254.169.254/1.0/user-data
will return
Some data I need

Be Sociable, Share!

One thought on “Finding information about an Amazon EC2 instance

  1. Hi can you tell me how can I access the instance id using a java program, like “http://169.254.169.254/1.0/instance-id”

Leave a Reply

Your email address will not be published. Required fields are marked *