当我在vpc中使用boto(python sdk for aws)给我的实例分配elastic 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 吗?
我已经在控制台看到了:
尝试:
conn = boto.ec2.connect_to_region(区域,aws_access_key_id='a-id',aws_secret_access_key='s-id',调试=2)
conn.associate_address(allow_reassociation=True, public_ip=kw['ip'], network_interface_id=nid, dry_run=True)
最佳答案
如果您使用 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)
这有帮助吗?
关于Python boto - 如何获取弹性 ip 的分配 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24114644/