Warm tip: This article is reproduced from stackoverflow.com, please click
amazon-web-services aws-cli boto jmespath

List volumes missing specific tags

发布于 2020-06-01 14:12:09

I am trying to list Volumes from the AWS CLI that is missing a specific tag key. While I can list volumes missing a specific key with below command.

aws ec2 describe-volumes  --query 'Volumes[?!not_null(Tags[?Key == `MakeSnapshot`].Value)] | [].[VolumeId]' --output text

Looking for logical OR operation inside the query statement by which I can list all the Volumes missing either of two keys something similar to this.

aws ec2 describe-volumes  --query 'Volumes[?!not_null(Tags[?Key == `MakeSnapshot|MakeDevSnapshot`].Value)] | [].[VolumeId]' --output text

Is it possible to perform such logical AND/OR operations within the query/James Path search?

Questioner
IgniteLX
Viewed
10
franklinsijo 2020-03-18 14:41

The JMESPath Specification for OR expressions uses ||. Reference here

Try,

aws ec2 describe-volumes  --query 'Volumes[?!not_null(Tags[?Key == `MakeSnapshot || MakeDevSnapshot`].Value)] | [].[VolumeId]' --output text