How to Retrieve EC2 Instance Meta Information

2020/04/011 min read
bookmark this
Responsive image

Table of Contents

  1. Introduction
  2. SSH into EC2 Instance
  3. Retrieve Metadata
  4. Conclusion

Introduction

This blog covers a few useful commands to retrieve metadata from an EC2 instance. EC2 instance metadata provides information about the running instance, such as hostname, IP address, and user data.

SSH into EC2 Instance

To retrieve EC2 instance metadata, first SSH into the EC2 instance and then run the following commands.

Run with root privileges

sudo su

Retrieve Metadata

List all the metadata

curl http://169.254.169.254/latest/meta-data

Get EC2's hostname

curl http://169.254.169.254/latest/meta-data/local-hostname

Get EC2's user data

curl http://169.254.169.254/latest/user-data

Conclusion

The EC2 instance metadata endpoint (169.254.169.254) provides a convenient way to retrieve information about your running instance without needing external tools. This is useful for automation scripts, configuration management, and debugging.