Search code examples
amazon-web-servicesaws-clijmespath

JMESPath multiple filters


I want to get instances with a tag that has a value.

aws ec2 describe-instances --query \
'Reservations[].Instances[? Tags[?Key==`datadog` && Value==`true`] ].Tags'

However I'm not getting my results this way. If I remove the && Value=='true' I'm getting the instances with datadog = true and datadog = false

What am I missing?


Solution

  • If you want to filter values, it is easier to use --filter than to try and code it into the --query.

    From describe-instances — AWS CLI Command Reference:

    To describe all instances with a Purpose=test tag

    aws ec2 describe-instances --filters "Name=tag:Purpose,Values=test"
    

    So you would use:

    aws ec2 describe-instances --filters "Name=tag:datadog,Values=true"