I want to run aws ec2 describe-instances
looking for any instances without a VpcId
property (those in ec2-classic)
How can I return ec2-classic instances using either the --query
flag or JMESPath expression to get results without a VpcId
?
This cli command will list all the instances which doesn't have VpcId
.
aws ec2 describe-instances --region us-east-1 --query 'Reservations[*].Instances[?!not_null(VpcId)] | [].[InstanceId]' --output text
You can tweak the same to list all instances which has VpcId
.
aws ec2 describe-instances --region us-east-1 --query 'Reservations[*].Instances[?not_null(VpcId)] | [].[InstanceId]' --output text