簡體   English   中英

如何獲取boto3中所有可用的彈性IP地址

[英]How to obtain all available Elastic IP addresses in boto3

什么是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()

此響應似乎不包含關聯狀態。

這是一個打印當前帳戶/區域中所有彈性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參考文檔

這可能有所幫助:

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

暫無
暫無

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

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