AWS cli List unused elb

Viewed 4461

I am pretty much new to AWS. I was trying to list the load balances which are not attached to any of the instances. I was trying describe-load-balancers using aws cli but was not able to get an option that filters the elbs.

Please provide some suggestions on how to achieve this.

2 Answers

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

Related