How Do You Find You out the AWS Instance ID from inside the OS of a Server?

Problem scenario
You are using AWS via web browser while using multiple Putty sessions are you logged into several AWS servers (aka AWS instances).  You can find the host names and internal IP addresses of the servers when you are logged into via the command line of the OS itself.  From the AWS console you can find external IP addresses and external FQDNs.  You do not know how to correlate these instances (as the information readily available in Putty at the OS level is independent of the information available via the AWS console).  You want to terminate one instance.  You want to know which instance ID (in the AWS console) corresponds to which OS you are using.  How do you find out which server is which?  

Solution
This solution does not require you to install the wget utility.  From a command prompt in Linux, run this command:

curl http://169.254.169.254/latest/meta-data/instance-id

The result of the above command will provide the instance ID.  This is readily available in the AWS console. Yes, it looks unusual to use a specific IP address in a URL. We believe the command should always work on an EC-2 instance -- regardless of your Security Group.

Leave a comment

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