Moshe
Moshe

Reputation: 5139

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?

Upvotes: 0

Views: 822

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269350

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"

Upvotes: 2

Related Questions