Python boto - 如何获取弹性 ip 的分配 id

标签 python amazon-ec2 boto

当我在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/

相关文章:

python - Mac OS X Mavericks 无法安装 MySQL-python==1.2.4

python - 使用Python模块BeautifulSoup抓取XML,需要树中的特定标签

amazon-web-services - 常规 AWS EC2 实例和 ml AWS EC2 实例有什么区别?

amazon-web-services - EC2 - 从 VPC 中删除 EC2

python - 如何判断 boto.sqs.Queue.write() 是否成功?

python - 如何使用 "conda list"输出 txt 安装 conda 包

python - 如何将超链接代码转换为普通的 URL 字符串?

php - 慢速 S3 -> EC2 传输。错误代码?

django - 使用 S3BotoStorage 上传到 S3 的文件最终会包含无效转义的内容类型元数据

boto - 弹性贴图减少: difference between CANCEL_AND_WAIT and CONTINUE?