How to Get and Set AWS EC2 Instance Metadata

How to Get and Set AWS EC2 Instance Metadata

Clear and comprehensive visibility into your cloud’s assets and footprint is critical in order to understand how your cloud and resources are being utilized. While Newvem provides you with complete visibility of your cloud resources’ lifecycle, you should also know what is required of getting and setting your AWS EC2 Instance metadata.

Amazon EC2 instances can access instance-specific metadata as well as data supplied when launching the instances. This data is useful to setup your instance or run some startup script. E.g. For a small company, they run a DB server and app in same instance. Now to connect to DB server, you need to provide the local IP (private DNS) of your instance. If you use AWS provided meta data, you can get the private DNS / IP and then make required changes to DB connection string so app connects to database using IP.

In this guide, we will see how you can get metadata. Some sample (default) metadata available from AWS.

Metadata is divided into categories. If you want the list of metadata categories it is available at

Instance metadata is nothing but AWS instance details like AMI ID, Public or private IP etc. Some sample meta data are listed below:

Requests for a specific metadata resource return the appropriate value or a 404 HTTP error code if the resource is not available. All metadata is returned as text (content type text/plain).

Though only your specific instance can access launch data, the data is not protected by cryptographic methods. You should take suitable precautions to protect sensitive data (such as long lived encryption keys). Also note that you are not billed for HTTP requests used to retrieve metadata and user-supplied data.

[Newvem ensures operational efficiency “do more with less” to build and manage a cloud that easily scales with your business. Newvem gives you the insights you need to better see, understand, assess and respond to vulnerabilities, abnormalities and other hidden issues. Learn More]

How to access the Instance metadata:

1.  Enter your AWS account Console, launch a linux instance and connect to it.

2.  To get the Instance metadata run: GET

3.  Run the Linux command /usr/bin/curl –s

4.  It will list the available metadata. If you want specific metadata like ami-id, public-ip or local ip run commands as shown in below image.

5.  A few more samples like get availability zone (here us-west-2b), instance-type (here micro), mac, security group, public host name of running instance is shown below.

6.  You can also run command wget instead of curl to get the instance metadata. Run command
wget –q –o -

7.  For example if you want to get ami-id using wget, run command
wget –q –o - to get AMI id.

8.  If you are in windows, you can run the command as SOAP call in browser or call from the AWS SDK / API.

9.  If you type in the browser , it will return all the instance metadata.

10.  Now if you want to query particular data send in the URL that metadata. E.g. If you want to know local IP of instance, type in the browser

How to add your  own metadata to an instance and get it from instance - 

12.  When you launch and instance, it asks to provide the metadata.

13.  If it is an EBS backed instance, you can stop the instance and provide the metadata.

15.  In order to get the metadata of Linux instance run the following command -
/usr/bin/curl –s

As shown above either you can get instance metadata or your own metadata in the instance. This option is very useful when you want to pass boot parameters or pass some instructions during instance boot. Also when you have to configure DB connection / register your instance with monitoring tool or some configuration management tool the metadata is very handful.


Understanding AWS Ec2 Instance Metadata

Understanding your Cloud Assets

Newvem presents you with a comprehensive picture of the resources in your cloud. With this you can:

  • Understand every single item you have in your cloud and see how they change over time. This includes compute instances (AWS EC2 and Reserved Instances), storage (AWS EBS and S3), network (AWS data transfer, Load Balancers, and Elastic IPs), security (AWS Security Groups and Access Control), and more.
  • Discover how your cloud resources are utilized, learn about utilization changes on an hourly basis, look back into historical usage patterns, and determine how your consumption is trending.
  • Detect abnormal utilization levels, resource over-provisioning, and policy deviations as well as receive best-practice and resource sizing recommendations.
  • Most importantly, gain full visibility of your cloud resources’ lifecycle.
For Cloud Operators

Now that you understand how to get and set AWS EC2 Instance Metadata, it’s time to understand what this means for you, as a cloud operator.

Newvem Cloud Care continuously tracks and analyzes your resources and utilization patterns, and provides a down-to-the-hour picture of your AWS consumption and usage behavior such as Elastic IP association (or disassociation) patterns. Newvem gives you the visibility you need to better understand, assess, and respond to vulnerabilities, abnormalities, and other hidden issues enabling you to:

  • Triage urgent cloud risks
  • Diagnose cost, risk, and governance issues
  • Track cloud cost and asset vitals

[Newvem Cloud Care provides comprehensive visibility into your EC2 footprint with drill downs from a consolidated view to a detailed resource status report. Newvem continuously analyzes your EC2 instance utilization patterns and provides a down-to-the-hour picture of your AWS EC2 consumption and usage.]

Keywords: Amazon web services, Amazon AWS console, EC2 Service, Amazon cloud computing, Linux Intance, Instance Metadata, AMI, EC2 Instance Image

There is 1 comment .

Shohel Khatri —

very helpful !! thnx cheers!!

You must be to post a comment.

* As a bonus, you'll receive our weekly newsletter!