【问题标题】:Could not get AWS load balancer details using get_all_load_balancers in boto无法在 boto 中使用 get_all_load_balancers 获取 AWS 负载均衡器详细信息
【发布时间】:2022-01-06 21:20:21
【问题描述】:

我正在尝试获取在 AWS 中创建的负载均衡器。

下面是我的代码

    elb_conn = boto.ec2.elb.connect_to_region(aws_access_key_id=AWSaccesskey, aws_secret_access_key=AWSsecretkey, region_name='us-east-1')
    elb_conn.get_all_load_balancers(['loadbalancername'])[0]

我得到的错误是

    Traceback (most recent call last):
      File "Praload.py", line 17, in <module>
        elb_conn.get_all_load_balancers(['loadbalancer1'])[0]
      File "/usr/local/lib/python2.7/site-packages/boto/ec2/elb/__init__.py", line 134, in get_all_load_balancers
        [('member', LoadBalancer)])
      File "/usr/local/lib/python2.7/site-packages/boto/connection.py", line 1186, in get_list
        raise self.ResponseError(response.status, response.reason, body)
    boto.exception.BotoServerError: BotoServerError: 400 Bad Request
    <ErrorResponse xmlns="http://elasticloadbalancing.amazonaws.com/doc/2012-06-01/">
      <Error>
        <Type>Sender</Type>
        <Code>LoadBalancerNotFound</Code>
        <Message>There is no ACTIVE Load Balancer named 'loadbalancername'</Message>
      </Error>
      <RequestId>131d2934-5bf6-11e7-92f6-17b72cd6bdf7</RequestId>
    </ErrorResponse>

boto 版本 = 2.47.0

python 版本 = 2.7

【问题讨论】:

  • 你为什么不不带参数调用get_all_load_balancers,看看你得到了什么,然后用现有的负载均衡器调用get_all_load_balancers
  • 我试过不带参数调用 get_all_load_balancers 但它只是给了我一个空列表。

标签: python amazon-web-services boto


【解决方案1】:

我知道这个问题有点老,但我认为错误消息与当前时代相关。 为了使用一个或另一个客户端,您必须考虑到您可能拥有的不同类型的 elb。 aws elb 适用于经典负载均衡器,但错误消息似乎指出您正在尝试获取其 应用程序、网络或网关负载均衡器的负载均衡器,因此我将使用 elbv2 而不是 boto3,像这样:

import boto3
client = boto3.client('elbv2', aws_access_key_id=AWSaccesskey, aws_secret_access_key=AWSsecretkey, region_name='us-east-1')
lbs = client.describe_load_balancers(Names=['loadbalancernamehere'])

【讨论】:

    【解决方案2】:

    ELB 有 2 种类型:ClassicV2

    您可以单独列出它们

    import boto3
    
    # Create clients for both types of ELBs
    elb_client = boto3.client('elb', region_name='us-west-1')
    elbV2_client = boto3.client('elbv2', region_name='us-west-1')
    
    
    
    # Get a list of classic ELBs
    elbs = elb_client.describe_load_balancers()['LoadBalancerDescriptions']
    elbs_list = [elb['LoadBalancerName'] for elb in elbs]
    
    
    
    # Get a list of V2 ELBs
    elbsv2 = elb_client.describe_load_balancers()['LoadBalancers']
    elbsv2_list = [elb['LoadBalancerArn'] for elb in elbsv2]
    

    【讨论】:

      猜你喜欢
      • 2019-10-06
      • 1970-01-01
      • 2020-10-24
      • 2023-01-23
      • 2014-12-18
      • 1970-01-01
      • 2018-02-18
      • 2013-08-26
      • 2018-04-14
      相关资源
      最近更新 更多