How to Find AWS EC2 Instance Type Over SSH (6 Methods)

Linux TLDR
Last Updated:
Reading time: 2 minutes

AWS provides a range of instance types, like t2.micro (eligible for the free tier), t3.micro, c5.large, and many more. When creating the AWS EC2 instance, you must select an instance type for which your next-month bill will be generated.

If you happen to forget the instance type chosen for your EC2 instance or if someone else deployed it, you can quickly check the EC2 instance type over SSH without logging into the AWS console.

In this article, I’ll introduce you to a few tools and command-line examples that can assist you in identifying the EC2 instance type. However, note that this example is solely for the AWS EC2 service, not Azure or GCP.

Tutorial Details

DescriptionFind an AWS EC2 Instance Type Over SSH
Difficulty LevelLow
Root or Sudo PrivilegesYes (for some examples)
OS CompatibilityUbuntu, Manjaro, Fedora, etc.
Prerequisites
Internet RequiredYes

Find an AWS EC2 Instance Type Over SSH

There are various ways to check the AWS EC2 instance type, including built-in options and external tools; the one I highly recommend is the “ec2-metadata” tool.

It’s an external tool, so you must first install it on your EC2 instance using one of the following commands, depending on your instance image.

# On Debian, Ubuntu, Linux Mint, Zorin OS, Pop!_OS, etc.
$ sudo apt install amazon-ec2-utils

# Red Hat, Fedora, CentOS, Rocky Linux, AlmaLinux, etc.
$ sudo dnf install amazon-ec2-utils

# On Arch, Manjaro, Garuda, etc (require Yay).
$ sudo yay -S ec2-metadata

# Using Python Package Manager.
$ python -m pip install ec2-metadata

Once the installation is complete, you can run the following command to get various metadata information related to your EC2 instance, such as AMI ID, block device mapping, instance ID, public/private IPv4, public/private hostname, and many more.

$ ec2-metadata

Output:

check aws ec2 instance metadata

To filter the output to only AWS EC2 instance types, you can use the following command:

$ ec2-metadata --instance-type

Output:

check aws ec2 instance type

Besides “ec2-metadata“, you can retrieve the AWS EC2 instance metadata from within a running instance, using the following curl commands:

# It's IMDSv2, where requests are authenticated and adds protections against SSRF (recommended).
$ 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" http://169.254.169.254/latest/meta-data/instance-type

# It's IMDSv1, where requests are unauthenticated and vulnerable to SSRF attacks (not work sometimes).
$ curl http://169.254.169.254/latest/meta-data/instance-type

Output:

check AWS ec2 instance type using IMDSv2 request

There are some additional built-in tools available for identifying the AWS EC2 instance type. Keep in mind, they might not work all the time, but it’s worth trying them out.

$ sudo dmesg | grep -Ew 'DMI|Amazon|EC2'

# OR

$ cat /sys/devices/virtual/dmi/id/product_name

# OR

$ sudo dmidecode -s system-product-name

If any of the above commands return the instance type, that’s great; otherwise, it might return HVM, which basically represents hardware-assisted virtualization used by Amazon for AWS EC2 instance creation.

Final Word

Currently, these are all the working methods available to help you find the AWS EC2 instance type. Most of these methods will flawlessly work on Unix/Linux, or FreeBSD virtual machines. If you’re a developer or SysAdmin and know additional ways to identify the instance type, please share in the comments.

Till then, peace!

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.