简体   繁体   中英

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

When I use boto(python sdk for aws) to assign elastic ip to my instance in vpc, it reported the following error:

    <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>

But I found nothing about allocation id in ec2-medata.

Anybody know how can I get allocation id from API?

I already seen it in console:

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)

If you use get_all_addresses it should return a list of Address objects which have an allocation_id attribute associated with them. The allocation_id will be non-None for any addresses that are associated with a VPC.

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)

Does that help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM