top of page

EC2 Linux Server Metadata

  • Writer: Parag
    Parag
  • Sep 22, 2020
  • 1 min read

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.



40 comentarios


Yogita Shinde
Yogita Shinde
01 may 2024

Well defined, easy to understand

Me gusta

VAISHNAVI M
VAISHNAVI M
31 ene 2024

very useful sir

Me gusta

Yamunadevi K
Yamunadevi K
31 ene 2024

Clearly explained sir

Me gusta

Rucha Kulkarni
Rucha Kulkarni
31 ene 2024

Well Explained


Me gusta

Shruti Bhosekar
Shruti Bhosekar
31 ene 2024

Very informative blog!

Me gusta
bottom of page