I'm trying to use the Amazon AWS Command Line Tools to find all instances that do not have a specified tag.
Finding all instances WITH a tag is simple enough, e.g.
ec2-describe-instances --filter "tag-key=Name"
But how would I invert that filter to return only the instances that have no tag "Name"?
To find resources that have an empty value for a tag, choose (empty value) when your cursor is in the tag value box. Before you can find resources with the specified tags, they must have been applied to at least one resource of the specified type in the current AWS Region.
On the Manage tags page, in Edit tags of selected resources, view the tags on the resource that you selected. Although your original query returned more resources, note that you are changing tags only on the resources that you selected in step 1. Change, add, or delete tag values.
Go to the instances section and click on "instances". It will show you all the running instances in the select region.
When you tag public or shared resources, the tags you assign are available only to your AWS account; no other AWS account will have access to those tags. For tag-based access control to shared resources, each AWS account must assign its own set of tags to control access to the resource. You can't tag all resources.
You can do that with jmespath (the engine that drives the --query
parameter) despite what others say:
aws ec2 describe-instances \ --query 'Reservations[].Instances[?!not_null(Tags[?Key == `Name`].Value)] | []'
Source: Using Amazon Web Services Command Line Interface (AWS CLI) to Find Instances without a 'Name' Tag.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With