7

boto3 相当于什么:

import boto

conn = boto.connect_ec2()
addresses = conn.get_all_addresses()

(返回所有弹性 IP 地址)

import boto3
ec2 = boto3.resource('ec2')
addresses = ec2.????

我对似乎也适用于 VPC 设置的概括有点困惑。


到目前为止,我发现如下:

import boto3

client = boto3.client('ec2')
print client.describe_addresses()

此响应似乎不包含关联状态。

4

2 回答 2

15

这是一个打印当前账户/区域中所有弹性 IP 公有 IP 地址的简单示例:

import boto3
client = boto3.client('ec2')
addresses_dict = client.describe_addresses()
for eip_dict in addresses_dict['Addresses']:
    print(eip_dict['PublicIp'])

有关更多信息,请参阅EC2.Client.describe_addresses 参考文档

于 2015-08-25T21:53:15.947 回答
1

这可能会有所帮助:

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')]

参考链接1

参考链接 2

于 2017-02-23T18:39:49.807 回答