top of page

EC2 Linux Server Metadata

Writer's picture: ParagParag

Updated: Jan 16, 2024

Tutorial blog to access instance metadata from a running instance


Learning Objective:

Learn to access instance metadata from a running instance using Instance Metadata Service Version 2 (IMDSv2)


Access instance metadata from a running instance using IMDSv2


Step 1: Provision a Linux instance using Amazon Linux 2023 AMI.

You may refer to our tutorial blog for step-by-step instructions to create & connect to the EC2 instance.

Step 2: Connect to the instance using EC2 instance connect.

Once you are connected to the instance your command prompt should display similar to the image below.

Step 3: To retrieve metadata run the following command.

TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/

Step 4: To retrievethe value of instance id run following command

TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/instance-id/

Similarly you can retrieve rest of the metadata for the instance.


Step 5: Close the SSH session and terminate the instance.


Was this document helpful? How can we make this document better. Please provide your insights. You can download PDF version for reference.



440 views40 comments

Recent Posts

See All

40 Comments


Yogita Shinde
Yogita Shinde
May 01, 2024

Well defined, easy to understand

Like

VAISHNAVI M
VAISHNAVI M
Jan 31, 2024

very useful sir

Like

Yamunadevi K
Yamunadevi K
Jan 31, 2024

Clearly explained sir

Like

Rucha Kulkarni
Rucha Kulkarni
Jan 31, 2024

Well Explained


Like

Shruti Bhosekar
Shruti Bhosekar
Jan 31, 2024

Very informative blog!

Like
bottom of page