top of page
  • Writer's pictureParag

EC2 Linux Server Metadata

Updated: Jan 16

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 "" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v

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

TOKEN=`curl -X PUT "" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` && curl -H "X-aws-ec2-metadata-token: $TOKEN" -v

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.

Download PDF • 421KB

421 views40 comments

Recent Posts

See All


Well defined, easy to understand


very useful sir


Clearly explained sir


Well Explained


Very informative blog!

bottom of page