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.
All AWS accounts are limited to five Elastic IP addresses per Region.
To describe your Elastic IP addressesOpen the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . In the navigation pane, choose Elastic IPs. Select the Elastic IP address to view and choose Actions, View details.
You're limited to five Elastic IP addresses. To help conserve them, you can use a NAT device. For more information, see Connect to the internet or other networks using NAT devices.
As the IPv4 public IP addresses are a scarce resource nowadays, by default, all AWS accounts are limited to 5 (five) Elastic IP addresses per region.
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')]
Reference Link 1
Reference Link 2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With