Get AWS Instance Info with ec2-metadata


If you are just starting with AWS, you may not know that Amazon Linux images have a special command for confirming most useful information about EC2 instance: ec2-metadata.

Instance info with ec2-metadata

If you just run the command without options, you’ll get to see all the available meta info.

Here’s an example from the instance (give me a shout if you want access to it for learning Linux!):

[[email protected] ~]$ ec2-metadata
ami-id: ami-466768ac
ami-launch-index: 0
ami-manifest-path: (unknown)
ancestor-ami-ids: not available
ami: /dev/xvda
root: /dev/xvda
instance-id: i-0fe057ab7e5ff2XYZ
instance-type: t2.nano
kernel-id: not available
placement: eu-west-1b
product-codes: not available
key:(begins from next line)
ssh-rsa //P6MR9UiNDVDOi7vZ7Um/O+nJwtfVNnqiPfzRFqvm11yIo1WmiyvC3Ilhcowqfd2WJBSb3gwuJVxZk9paBp+CvVU2i99OJO+ss10656g3hBgS2xlMatPWyM/Ab6uZOO0X6NbTL/kSbThsnSyZadue36Qt1pcPWoIp0cV unixtutorial
ramdisk-id: not available
reservation-id: r-0b1d0abebXYZ
security-groups: launch-wizard-15
user-data: not available

Command line options for ec2-metadata

There are also lots of command line options to show individual fields from this output.

Confirm AMI image ID with ec2-metadata

[[email protected] ~]# ec2-metadata -a
ami-id: ami-466768ac

Confirm Current EC2 Instance ID with ec2-metadata

[[email protected] ~]# ec2-metadata -i
instance-id: i-0fe057ab7e5ff2f1d

Confirm Internal IP addresses with ec2-metadata

[[email protected] ~]# ec2-metadata -o

Confirm external IP address with ec2-metadata

This will only work if you actually have external IPv4 address mapped to your instance.

[[email protected] ~]# ec2-metadata -v

Are you interested in more AWS related posts and Unix tutorials? Please let me know!

See Also

Keep Learning with Me

Follow me on Facebook and Twitter or jump into Telegram chat!:
Recommended Software
I use Brave browser, it's awesome: Brave Browser I'm also a fan of SetApp for macOS: SetApp for macOS
IT Consultancy
I'm a principal consultant with Tech Stack Solutions. I help with cloud architectrure, AWS deployments and automated management of Unix/Linux infrastructure. Get in touch!

Recent Tweets