【问题标题】:Python boto - How can I get allocation id of elastic ipPython boto - 我如何获得弹性ip的分配ID
【发布时间】:2019-03-13 04:37:19
【问题描述】:

当我在vpc中使用boto(python sdk for aws)给我的实例分配弹性ip时,报如下错误:

    <Response>
      <Errors>
         <Error>
           <Code>InvalidParameterCombination</Code>
           <Message>You must specify an allocation id when mapping an address to a network interface</Message>
    </Error>
    </Errors>
    <RequestID>d0f95756-c36f-417a-9fa9-1158c4aa19e9</RequestID>
</Response>

但是我在 ec2-medata 中没有发现任何关于分配 id 的信息。

有人知道我如何从 API 获取分配 id 吗?

我已经在控制台看到了:

try: conn = boto.ec2.connect_to_region(zone, aws_access_key_id='a-id', aws_secret_access_key='s-id',debug=2) conn.associate_address(allow_reassociation=True, public_ip=kw['ip'], network_interface_id=nid, dry_run=True)

【问题讨论】:

  • 尝试:conn = boto.ec2.connect_to_region(zone, aws_access_key_id='aid', aws_secret_access_key='sid',debug=2) if kw.has_key('type') and kw['type '] == 'elastic': conn.associate_address(allow_reassociation=True, public_ip=kw['ip'], network_interface_id=nid, dry_run=True) else: conn.assign_private_ip_addresses(allow_reassignment=True, network_interface_id=nid, private_ip_addresses=kw ['ip'])
  • 这不可读 - 请将其添加到您的问题中,格式化等。

标签: python amazon-ec2 boto


【解决方案1】:

如果您使用get_all_addresses,它应该返回一个Address 对象列表,这些对象具有与之关联的allocation_id 属性。对于与 VPC 关联的任何地址,allocation_id 将不是 None。

import boto.ec2
c = boto.ec2.connect_to_region('us-east-1')
addresses = c.get_all_addresses()
for addr in addresses:
    print('%s - %s' % (addr.public_ip, addr.allocation_id)

这有帮助吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-07-28
    • 2013-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多