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 "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.


EC2_Instance_Metadata
.pdf
Download PDF • 421KB

419 views40 comments

Recent Posts

See All
bottom of page