In general you can get a lot of instance metadata by accessing API on
That includes instance id.
On generic Linux system, you can get the ID either using curl:
wget -q -O - http://169.254.169.254/latest/meta-data/instance-id
If you instance is based on Amazon Linux or have cloud-utils installed you can also run:
for instance id.
more documentation on metadata is a available here:
Provided by:Forthscale systems, cloud experts