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.