I saw the answers above and wanted to craft the answers using jq
instead of Bash
or Boto
.
The following examples utilize jq
with AWS cli.
This example solves what the OP was originally trying to do --
List ELB's without instances attached:
aws elb describe-load-balancers --output json |jq -r '.LoadBalancerDescriptions[] | select(.Instances==[]) | . as $l | [$l.LoadBalancerName] | @sh'
Output
'blah10-admin'
'elk-elb-nova'
'cj-web-elb'
This example matches the accepted answer --
Print the ELB name and count of attached instances:
aws elb describe-load-balancers --output json | jq -r '.LoadBalancerDescriptions[] | . as $l | (.Instances | length) as $i | [$l.LoadBalancerName] + [$i] | @sh'
Output
'blah10-admin' 0
'elk-lb-cim-0' 1
'demo-pod-01-es' 1
'elk-elb-nova' 0