What is the boto3 equivalent to:
import boto
conn = boto.connect_ec2()
addresses = conn.get_all_addresses()
(returning all Elastic IP addresses)
import boto3
ec2 = boto3.resource('ec2')
addresses = ec2.????
I am a little bit confused by the generalization that seem to apply to VPC setups as well.
What I found so far is following:
import boto3
client = boto3.client('ec2')
print client.describe_addresses()
This response does not seem to contain the association status.
Here's a simple example that prints all Elastic IP public IP addresses in the current account/region:
import boto3
client = boto3.client('ec2')
addresses_dict = client.describe_addresses()
for eip_dict in addresses_dict['Addresses']:
print(eip_dict['PublicIp'])
For more, see the EC2.Client.describe_addresses reference documentation .
This may help:
import boto3
ec2 = boto3.resource('ec2', region_name="ap-southeast-1")
client = boto3.client('ec2', region_name="ap-southeast-1")
# create 3 x Elastic IP Addresses. Set to Domain='vpc' to allocate the address for use with instances in a VPC.
eip1 = client.allocate_address(Domain='vpc')
eip2 = client.allocate_address(Domain='vpc')
eip3 = client.allocate_address(Domain='vpc')
# A collection of VpcAddresses resources "vpc_addresses.all()"
print eip = list(ec2.vpc_addresses.all())
[ec2.VpcAddress(allocation_id='eipalloc-3f693f5a'), ec2.VpcAddress(allocation_id='eipalloc-7896c01d'),
ec2.VpcAddress(allocation_id='eipalloc-9997c1fc')]
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.