AWS CLI列表未使用的Elb [英] AWS cli List unused elb

查看:126
本文介绍了AWS CLI列表未使用的Elb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对AWS几乎是新手.我试图列出未附加到任何实例的负载平衡.我正在尝试使用aws cli来描述负载均衡器,但无法获得过滤弯头的选项.

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.

推荐答案

假定您已使用适当的键设置了aws cli设置,那么这一行长长的外壳应列出带有附加实例数的ELB.如果显示为零,则表示没有附加实例

Assuming you have aws cli setup with suitable keys, this long line of shell should list the ELBs with a count of instances attached to them. If it says zero then there are no instances attached

for i in `aws elb describe-load-balancers|sed -ne 's/"LoadBalancerName": "\(.*\)",/\1/gp'`; do echo -n "$i "; aws elb describe-load-balancers --load-balancer-name $i|grep -c InstanceId;done

或者,这是一个boto3 python程序

Alternatively, here's a boto3 python program

import boto3
client=boto3.client('elb')
bals=client.describe_load_balancers()
for elb in bals['LoadBalancerDescriptions']:
  count=len(elb['Instances'])
  print "%s %d" % ( elb['LoadBalancerName'], count)

这篇关于AWS CLI列表未使用的Elb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆