Python 3.x 使用AWS SDK for python访问AWS弹性负载平衡器

Python 3.x 使用AWS SDK for python访问AWS弹性负载平衡器,python-3.x,amazon-web-services,boto3,Python 3.x,Amazon Web Services,Boto3,因此,我使用boto3连接到AWS并管理我的web服务器实例,这些实例位于弹性负载平衡器(ELB)后面。问题是我没有访问我的ELB的权限,而我可以访问其他现有资源,如实例。例如,当我运行这段代码时,我可以看到我正在运行的实例: ec2 = boto3.resource('ec2', region_name="us-east-2") instances = ec2.instances.all() for instance in instances.all(): print(instanc

因此,我使用boto3连接到AWS并管理我的web服务器实例,这些实例位于弹性负载平衡器(ELB)后面。问题是我没有访问我的ELB的权限,而我可以访问其他现有资源,如实例。例如,当我运行这段代码时,我可以看到我正在运行的实例:

ec2 = boto3.resource('ec2', region_name="us-east-2")
instances = ec2.instances.all()
for instance in instances.all():
     print(instance)
输出如下:

ec2.Instance(id='i-xxxxxxxxxxxxxxxxx')
ec2.Instance(id='i-xxxxxxxxxxxxxxxxx')
ec2.Instance(id='i-xxxxxxxxxxxxxxxxx')
{'LoadBalancerDescriptions': [], 'ResponseMetadata': {'RequestId': 'f813b2d3-b5e8-11e7-8b34-73b6f3d263a2', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'f813b2d3-b5e8-11e7-8b34-73b6f3d263a2','content-type': 'text/xml', 'content-length': '335', 'date': 'Fri, 20 Oct 2017 22:49:45 GMT'}, 'RetryAttempts': 0}}
通过运行以下代码,我希望看到我的ELBs:

elb = boto3.client('elb', region_name="us-east-2")
elbs = elb.describe_load_balancers()
print(elbs)
但是输出是这样的:

ec2.Instance(id='i-xxxxxxxxxxxxxxxxx')
ec2.Instance(id='i-xxxxxxxxxxxxxxxxx')
ec2.Instance(id='i-xxxxxxxxxxxxxxxxx')
{'LoadBalancerDescriptions': [], 'ResponseMetadata': {'RequestId': 'f813b2d3-b5e8-11e7-8b34-73b6f3d263a2', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'f813b2d3-b5e8-11e7-8b34-73b6f3d263a2','content-type': 'text/xml', 'content-length': '335', 'date': 'Fri, 20 Oct 2017 22:49:45 GMT'}, 'RetryAttempts': 0}}
正如您在输出中看到的,在
LoadBalancerDescriptions
中没有ELB,而根据,它应该包含现有ELB的名称。但我的控制台中有一个ELB,工作正常:


我不知道为什么python代码不起作用

对于较新的负载平衡器:ALB和NLB,使用ElasticLoadBalancingV2类。示例:client=bot3.client('elbv2')


将类ElasticLoadBalancement用于“经典负载平衡器”