'Can you do AND/OR type queries with the AWS CLI?

I would like to use AND OR style bitwise operatirs with an AWS CLI query.

Specifically, I would like to find all of our load balancers that are:

  1. internet facing (Scheme == "internet=facing")
  2. use https (Protocol == "HTTPS")
  3. are not limited to just TLS1.2 (PolicyNames != "ELBSecurityPolicy-TLS-1-2-2017-01")

If I do a base query for just one of the criteria, it works:

aws elb describe-load-balancers --query "LoadBalancerDescriptions[].ListenerDescriptions[?PolicyNames!='ELBSecurityPolicy-TLS-1-2-2017-01']"

If I try to add to that with one more criteria, it fails:

aws elb describe-load-balancers --query "LoadBalancerDescriptions[].ListenerDescriptions[?PolicyNames!='ELBSecurityPolicy-TLS-1-2-2017-01'], LoadBalancerDescriptions[].ListenerDescriptions[?Scheme=='internet-facing']"

Eventually, I would like for it to output the Name, DNS, and ideally, the CFT it is tied to, but only the internetfacing HTTPS ports that are not restricted to TLS1.2



Solution 1:[1]

I think I figured it out:

aws elb describe-load-balancers --query "LoadBalancerDescriptions[?Scheme=='internet-facing'].[LoadBalancerName, DNSName, ListenerDescriptions[?PolicyNames!='ELBSecurityPolicy-TLS-1-2-2017-01'], ListenerDescriptions[*].Listener[?Protocol=='HTTPS']]"

Still not sure the best way to link it to the CFTs via a CLI command, but getting closer. :-)

Solution 2:[2]

You could also use the pipe operator | to simulate a boolean AND, like this:

aws ec2 describe-images --owner amazon --query 'Images[?Name!=`null`]|[?starts_with(Name, `aws-elasticbeanstalk`) == `true`]|[0:5].[ImageId,Name]' --output text

I got this example from here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 John Rotenstein
Solution 2 Peter Störmer