Sometimes you might not have access to the AWS Console or just have direct access to an EC2 instance and would like to find out more information on the EC2 instance itself and where it’s hosted in AWS Cloud. The quickest way to fetch or retrieve EC2 instance metadata from within a running EC2 instance is to log in and run the command: Fetch metadata from IPv4: curl -s http://169.254.169.254/latest/dynamic/instance-identity/document

The instance metadata is a document that stores information about the identity of the EC2 instance which can only be accessed from within the instance.

AWS provides a default IP address that can be used to query the EC2 instance metadata from within a running EC2 instance.

Run the following command on the EC2 instance to get its AMI ID: curl -s http://169.254.169.254/latest/meta-data/ami-id

Related Articles