Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EC2: get instance id from within the instance itself [duplicate]

Possible Duplicate:
Find out the instance id from within an ec2 machine

I am looking for the simplest way to find the id of an instance from within this instance itself.

I looked at the shell variables: no luck. How can I get it ?

My only solution right now is to write to the java api (1) to describe instances and (2) to finding the one matching ip address or dns and get its id. Anything simpler ?

thanks

didier

like image 867
Didier Durand Avatar asked Feb 21 '11 08:02

Didier Durand


1 Answers

You can use the Instance Metadata API to retrieve the instance ID. Simply make a HTTP GET request to http://169.254.169.254/latest/meta-data/instance-id from within the instance.

like image 121
bdonlan Avatar answered Sep 28 '22 00:09

bdonlan