Search code examples
amazon-web-servicesaws-clibotojmespath

List volumes missing specific tags


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?


Solution

  • 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