簡體   English   中英

Python boto - 如何獲得彈性ip的分配ID

[英]Python boto - How can I get allocation id of elastic ip

當我使用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-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)

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

這有幫助嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM