Examples of EC2 Instance Metadata outputs

Photo by Ricardo Gomez Angel on Unsplash

I was trying to compare Ansible facts with EC2 instance metadata, to check if instance metadata provides the same level of detail as Ansible does. But after a minute of searching, I didn’t find an example output returned from a call to 169.254.169.254 or fd00:ec2::254, the IP addresses where the metadata service lives. It’s probably out there, but I figured I would make this more googleable for future me, and anyone out there with the same question.

A description of each of the items in EC2 instance metadata is available in the guide on dynamic data categories, but I wanted to see the full output with sample values.

Shout out to Ahmet Alp Balkan for writing a more comprehensive comparison of instance metadata across cloud providers. In this post, I’m just giving examples of outputs.

My takeaways

The output of the below example’s Ansible facts is 456 lines long, and the EC2 instance metadata output in the other example is 126 lines long. Ansible facts give you a lot more system-level information than EC2 instance metadata, down to details like:

  • the package manager
  • the date and time, in many formats
  • info on eth0, like netmask

EC2 instance metadata, however, is able to give you details specific to AWS, pulling in data from other services. For example:

  • the IAM role associated with the instance
  • security groups
  • reservation ID

Ansible, in its community.aws collection, has modules that can retrieve AWS-specific information. Search for “info” or “facts” on the list of modules. And there’s a module from which you can return security group information with ec2_group_facts.

Example output of Ansible facts for CentOS 7

Ansible facts output example from Ansible official documentation

Example output of EC2 Instance Metadata for Amazon Linux 2

To get the output in a readable format, I adapted Vipin Ajayakumar’s python script to include not just /meta-data but also /dynamic. The script recurses through 169.254.169.254/latest and converts the output to JSON:

Vipin Ajayakumar (bluprince13)’s script, adapted to include /dynamic. The script gets all the output from EC2 instance metadata and outputs it in JSON format.

I ran it on an “Amazon Linux 2 AMI (HVM) — Kernel 5.10, SSD Volume Type — ami-002068ed284fb165b (64-bit x86)” instance. Here’s the redacted output of the meta-data portion of the EC2 instance metadata:

EC2 instance metadata /meta-data output.

The dynamic portion of EC2 instance metadata:

EC2 instance metadata /dynamic output.

Comparison of Access

With Ansible, you can refer to an item in the facts like {{ ansible_facts[‘devices’][‘xvda’][‘model’] }}.

With EC2, you can curl 169.254.169.254/latestand append the path you want to that, like curl 169.254.169.254/latest/meta-data/ami-id.

I hoped that saved you a few minutes! Leave a comment to share your experiences with Ansible facts and EC2 instance metadata, or if you have any cool approaches to using these.

--

--

--

Solutions Architect. 13x AWS certified. All opinions are my own. Support this blog and others by becoming a member here: https://ystoneman.medium.com/membership

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Managing and scaling different white label development and testing environments

Decentralized Gaia-X Federations enable freedom of choice for cloud adoption

“NO-CODE DEVELOPMENT PLATFORM”

Chain of responsibility Design Pattern

Diamond operator for Anonymous Inner Classes

Docker, the Whale itself!

AWS Lambda

3 Tips to Solve Writing Contention Problems in Google Datastore

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Yann Stoneman

Yann Stoneman

Solutions Architect. 13x AWS certified. All opinions are my own. Support this blog and others by becoming a member here: https://ystoneman.medium.com/membership

More from Medium

SAP Monitoring using AWS Data Provider for SAP

Amazon S3: Features and Storage Classes

Beginners Guide to AWS — Virtual Private Cloud [VPC]

Cloud providers from a developer perspective