Linux.com

Home Linux Community Community Blogs General Linux Accessing Amazon EC2 Instance information from the command line using curl

Accessing Amazon EC2 Instance information from the command line using curl

If you use Amazon Web Services EC2 for virtualising your infrastructure, you may find that once you have a few instances started, that it may be hard (especially if you aren't using a configuration management tool) to trace back 'which machine belongs to what security group?' or 'which AMI did I use to bring up this instance?.'

 

Well theres a few quick tricks you can use to get some info out of your running instances. To do this you need to access the instances meta-data, and this is available simply by using 'Curl' from your running Linux instance, as follows:

 

'curl http://169.254.169.254/latest/meta-data/<metadata-object>'

 

here are some of the metadata objects:

ami-launch-index

ami-manifest-path

block-device-mapping/

hostname

instance-action

instance-id

instance-type

kernel-id

local-hostname

local-ipv4

placement/

profile

public-hostname

public-ipv4

public-keys/

reservation-id

security-groups

 

ami-manifest-path will tell you from where on AWS the AMI (the Amazon Machine Image for the linux virtual machine) was launched. If you rolled/composed your own AMI this helps you match up which Bucket on S3 relates to your AMI.

 

for example:curl http://169.254.169.254/latest/meta-data/ami-manifest-path

 

 

public-ipv4 is the world-facing IP address of the running virtual machine.

 

If your not sure from looking at the AWS Dashboard (or dont have access to it) you can run:

 

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

 

this will help you make sure if you want to terminate an instance that you kill off the correct one.

 

Its easy to experiment with, and the fact that you use curl to access the metadata information, it means that its also something thats pretty easy to compose a shell script for commonly needed tasks.

Hope someone finds this helpful.

 

Comments

Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFS426 Linux Performance Tuning
    08 Sep » 11 Sep - New York
    Details
  2. LFS520 OpenStack Cloud Architecture and Deployment
    08 Sep » 11 Sep - Virtual
    Details
  3. LFD320 Linux Kernel Internals and Debugging
    15 Sep » 19 Sep - Virtual
    Details

View All Upcoming Courses


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board