我正在尝试通过以下代码检查所有区域是否有ELB资源:
elb = boto3.client("elbv2")
x = elb.describe_load_balancers()
x = x["LoadBalancers"]
print(x)
n=0
for entity in x:
for k, v in entity.items():
if k == "LoadBalancerName":
n+=1
print(n)
这仅签入已配置的默认区域。我可以传递一个参数来指定python中的所有区域吗?
答案 0 :(得分:0)
您需要遍历每个区域,然后执行检查。像这样:
# Get a list of Regions
ec2 = boto3.client('ec2')
region_list = [region['RegionName'] for region in ec2.describe_regions()['Regions']]
# Loop through each region
for region in region_list:
# Connect to ELB in given region
elb = boto3.client("elbv2", region_name=region)
x = elb.describe_load_balancers()
...