【问题标题】:AWS- Associating a VPC with load balancer creation using boto APIAWS- 使用 boto API 将 VPC 与创建负载均衡器相关联
【发布时间】:2015-01-20 11:36:22
【问题描述】:

我对使用 boto 进行自动化比较陌生,并创建了一个脚本,该脚本使用 python 的 boto API 在 AWS 上设置自动扩展基础设施。

但是,我无法将我的 VPC 与我的负载均衡器创建相关联。以下代码返回格式错误的输入错误:

zoneStrings = 'eu-west-1a', 'eu-west-1b' #The availability zones of my VPC
elb_conn = boto.ec2.elb.connect_to_region('eu-west-1') #

lb_name = 'my-lb'
zones = zoneStrings
subnets = 'subnet-09519f50', 'subnet-9fa12dfa' #VPC subnets
ports= [(80, 80, 'http'), (443, 443, 'tcp')]
lb = elb_conn.create_load_balancer(lb_name, zones, subnets, ports)

完整的错误是:

  Traceback (most recent call last):
  File "./test.py", line 70, in <module>
    lb = elb_conn.create_load_balancer(lb_name, zones, subnets, ports)
  File "/usr/local/lib/python2.7/dist-packages/boto/ec2/elb/__init__.py", line 243, in create_load_balancer
    params, LoadBalancer)
  File "/usr/local/lib/python2.7/dist-packages/boto/connection.py", line 1207, in get_object
    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>MalformedInput</Code>
  </Error>
  <RequestId>12659703-a021-11e4-9488-1f8ceceab6a1</RequestId>
</ErrorResponse>

任何见解将不胜感激。

【问题讨论】:

    标签: python amazon-web-services load-balancing boto amazon-vpc


    【解决方案1】:

    boto 文档指出create_load_balancer 方法的参数顺序为:

    • 姓名
    • 区域
    • 听众
    • 子网
    • ...

    您似乎以不同的顺序提供它们。也许最安全的方法是使用关键字参数而不是依赖位置顺序。所以:

    lb = elb_conn.create_load_balancer(name=lb_name, zones=zones, subnets=subnets, listeners=ports)
    

    这对你有用吗?

    【讨论】:

    • 感谢您的帮助:以下工作 lb = elb_conn.create_load_balancer(name=lb_name, zone=zones, subnets=subnets, listeners=ports, security_groups=sg)。奇怪的是,文档顺序是子网之前的侦听器,这对我不起作用。 boto.readthedocs.org/en/latest/ref/…
    • 另外,zone 的值必须为 none,否则会导致与 vpc 子网冲突。
    猜你喜欢
    • 2019-07-14
    • 2017-01-25
    • 2017-11-07
    • 1970-01-01
    • 2019-01-10
    • 2014-12-18
    • 1970-01-01
    • 2021-05-08
    • 1970-01-01
    相关资源
    最近更新 更多