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"?
You can do that with jmespath (the engine that drives the
--query
parameter) despite what others say:Source: Using Amazon Web Services Command Line Interface (AWS CLI) to Find Instances without a 'Name' Tag.
Since
--filters
parameter doesn't seem to support inverse filtering, here's my solution to this problem using--query
parameter:It looks at an array of tag keys for each instance and filters those instance that don't have Tag 'Name' in the array. Then flattens output to array of instance IDs.
jq
or other command to filter output.