python - boto3 describe_load_balancers() 什么都不显示,而 aws-cli 显示所有
问题描述
在用 boto3 敲了一阵子之后,我决定做一个健全性检查,以确保我在 AWS 控制台中看到的 elb 和 alb 确实存在。
aws elbv2 describe-load-balancers
和
aws elb describe-load-balancers
都显示结果。
但是,此代码显示为空(没有错误,但没有结果):
import boto3
def all_lb(lb_type,*args):
try:
if lb_type == 'alb':
elb = boto3.client('elbv2')
elif lb_type == 'elb':
elb = boto3.client('elb')
except Exception as exc:
print(exc)
exit(1)
elb.describe_load_balancers()
print("---- ELB's")
all_lb(lb_type='elb')
print("---- ALB's")
all_lb(lb_type='alb')
我在这里做错了什么?
解决方案
结果在 elb.describe_load_balancers()
import boto3
def all_lb(lb_type,*args):
try:
if lb_type == 'alb':
elb = boto3.client('elbv2')
name = 'LoadBalancers'
elif lb_type == 'elb':
elb = boto3.client('elb')
name = 'LoadBalancerDescriptions'
except Exception as exc:
print(exc)
exit(1)
bals = elb.describe_load_balancers()
for elb2 in bals[name]:
print(elb2['LoadBalancerName'])
print("---- ELB's")
all_lb(lb_type='elb')
print("---- ALB's")
all_lb(lb_type='alb')
推荐阅读
- java - 如何用 JMH 测量平均冷启动时间?
- c# - 使用 NPOI 包导出 excel 文件
- c++ - 我无法在 Visual Studio 2019 中访问我的 C++ 程序文件
- flutter - 列表/数组初始化的更好实践
- c++ - c ++多维地图:如何尊重第二个关键?
- laravel - 通过 laravel-socialite 后端的社交帐户登录用户
- python - 无法使用 python 脚本从 Jenkins 发送电子邮件
- c# - Selenium Chrome webdriver偶尔挂起c#
- c# - 选择日期时如何关闭紧凑的 UIDatePicker 弹出窗口?
- xamarin - Xamarin.iOS 链接器和反射问题