How to identify an EC2 Classic Instance

Viewed 3351

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.

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.

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.

Related