Finding all Amazon AWS Instances That Do Not Have a Certain Tag

前端 未结 9 2020
借酒劲吻你
借酒劲吻你 2020-12-23 12:09

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.<

9条回答
  •  感情败类
    2020-12-23 12:23

    Unfortunately the underlying api call DescribeSnapshots does not support inverse tag filtering, and so neither does the CLI. You can, however, do client side filtering with the --query parameter which performs a JMESPath search. This will prevent you from having to use pipes as with user2616321's answer.

    For example:

    aws ec2 describe-instances --query "Reservations[].Instances[?Tags[?Key == 'Name']][]"
    

    Add .InstanceId to the end of that to just get the instance ids.

提交回复
热议问题