Possible: AWS CLI Describe Not Equal To

时间:2016-04-04 17:02:22

标签: amazon-web-services aws-cli

I am currently using the AWS CLI to select instances and I have the following query:

aws ec2 describe-instances --filter "Name=instance.group-name,Values=my-cluster" "Name=instance-state-name,Values=running,pending,stopped" 'Name=tag:Name, Values=someInstance*'

This works and selects all the instances that start with someInstance.

However, I want to do the opposite, select all other instances that do NOT match this. I have tried using a regex but this doesn't work:

aws ec2 describe-instances --filter "Name=instance.group-name,Values=my-cluster" "Name=instance-state-name,Values=running,pending,stopped" 'Name=tag:Creater, Values=^(?!someInstance).*$'

Is this possible?

1 个答案:

答案 0 :(得分:3)

这可以通过使用JQ -

来完成
aws ec2 describe-instances --filter "Name=instance.group-name,Values=my-group" "Name=instance-state-name,Values=running,pending,stopped" | jq '.Reservations[].Instances[] |  select(contains({Tags: [{Key: "Creator"}^C{Value: "myExclusion"}]}) | not)'