Python boto - 如何获得弹性ip的分配ID

问题描述 投票:3回答:1

当我使用boto(用于aws的python sdk)将弹性ip分配给我在vpc中的实例时,它报告了以下错误:

    <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-metadata中的分配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)

python amazon-ec2 boto
1个回答
2
投票

如果你使用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)

这有帮助吗?

© www.soinside.com 2019 - 2024. All rights reserved.