2017-10-21 155 views
1

因此,我使用boto3连接到AWS并管理位于Elastic Load Balancer(ELB)后面的Web服务器实例。问题是我没有访问我的ELB,这是我有权访问像Instances这样的其他现有资源。例如,当我运行这段代码,我可以看到我正在运行的实例:使用适用于python的AWS开发工具包访问AWS Elastic Load Balancer

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') 

通过运行下面的代码,我希望看到我ELBs:

elb = boto3.client('elb', region_name="us-east-2") 
elbs = elb.describe_load_balancers() 
print(elbs) 

但输出是这样的:

{'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,而根据API refference,它应该包含现有ELB的名称。但是,我有我的控制台ELB工作正常:

The existing ELB in my AWS console

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

回答

2

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

对“Classic Load Balancer”使用ElasticLoadBalancing类。

ElasticLoadBalancingv2

相关问题