Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to identify an EC2 Classic Instance

Recently got an email titled, "Important News from AWS About Amazon EC2-Classic" describing some changes that need to occur. These emails from AWS usually reference the effected resources though and this one did not. I am having a hard time identifying what resources in our account are effected by this. All our EC2 instances are in a VPC and I am not even sure if anything needs to change or not.

Is there a way to identify that an EC2 instance is classic?

I have looked through their linked documentation and gone through the instances we have but I cannot tell if they are "classic" of not.

like image 545
Rockwell Rice Avatar asked Aug 11 '21 21:08

Rockwell Rice


People also ask

How do I know if my EC2 is a classic instance?

On the EC2 dashboard, check the “Account Attributes”. If the supported platform status set to VPC and EC2, then the selected account support both EC2-Classic and EC2-VPC platforms. Select the “Instances” option on the left navigation panel to verify whether any instances are lunch under “EC2-Classic.”

What is classic EC2 instance?

With EC2-Classic, your instances run in a single, flat network that you share with other customers. With Amazon VPC, your instances run in a virtual private cloud (VPC) that's logically isolated to your AWS account. The EC2-Classic platform was introduced in the original release of Amazon EC2.

How do I find my EC2 instance details?

You can use EC2 Instance Metadata Query Tool which is a simple bash script that uses curl to query the EC2 instance Metadata from within a running EC2 instance as mentioned in documentation. now run command to get required data.


2 Answers

You can identify the EC2-Classic env by checking the instance has VPC ID or not.

EC2 console

VPC ID is not shown by default. Enable VPC ID from Preference -> Attribute columns.

Then if VPC ID attribute is -, that means the instance is EC2-Classic. (Except that the instance state is not terminated.)

CLI

2 ways for checking. Output is none unless EC2-classic instances exist.

  • Describe instance with EC2-Classic env.
aws ec2 describe-instances --filters Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped | jq '.Reservations[].Instances[] | select(.VpcId == null)'
  • Describe the instance if it is the EC2-Classic.
aws ec2 describe-instances --instance-id i-xxxxxxxxxxxx --filters Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped | jq '.Reservations[].Instances[] | select(.VpcId == null)'

jq select for terminated state

This is another way to filter the result of aws ec2 describe-instances. Adding .State.Name != "terminated" and in jq select works the same as --filters .... This might be more readable.

aws ec2 describe-instances | jq '.Reservations[].Instances[] | select(.State.Name != "terminated" and .VpcId == null)'

Edit note: Thanks to the suggestion from @AUdden, I have modified the CLI code for filtering out the terminated state. When we terminated instances (not stop), the instances exist for a while in terminated state. The terminated instances are not associated with VPC anymore. To do that, I have added --filters Name=instance-state-name,Values=pending,running,shutting-down,stopping,stopped.

like image 197
shimo Avatar answered Nov 15 '22 06:11

shimo


Amazon provides a script to identify all resources affected by the retirement, including resources you may not consider such as security groups.

Important: Check the file errors.txt after running the script. The script will happily run through its steps even if there is an error (such as missing/wrong credentials) without showing any hint of trouble in the console output.

like image 35
Eric J. Avatar answered Nov 15 '22 07:11

Eric J.