簡體   English   中英

在 boto 中獲取 vpc 對等連接 ID

[英]fetch vpc peering connection id in boto

我希望在 boto 中檢索 vpc 對等連接 ID,這將由“aws ec2 describe-vpc-peering-connections”完成。 我找不到它的 boto 等價物。 是否可以在 boto 中檢索它?

boto3 與之前的 boto 不同。 這是 boto3 中的解決方案:

import boto3
prevar = boto3.client('ec2')
var1 = prevar.describe_vpc_peering_connections()
print(var1)

在 boto 中,您將使用boto.vpc.get_all_peering_connections() ,如下所示:

import boto.vpc
c = boto.vpc.connect_to_region('us-east-1')
vpcs = c.get_all_vpcs()
vpc_peering_connection = c.create_vpc_peering_connection(vpcs[0].id, vpcs[1].id)

獲取所有 vpc 對等互連 ID

import boto.vpc
conn = boto.vpc.connect_to_region('us-east-1')
vpcpeering = conn.get_all_vpc_peering_connections()
for peering in vpcpeering:
   print peering.id

如果您知道接受者 VPC id 和請求者 vpc ID,您應該通過以下方式獲取 vpc 對等互連 id:

import boto.vpc
conn = boto.vpc.connect_to_region('us-east-1')
peering = conn.get_all_vpc_peering_connections(filters = {'accepter-vpc-info.vpc-id' = 'vpc-12345abc','requester-vpc-info.vpc-id' = 'vpc-cba54321'})[0]
print peering.id

如果這是您環境中唯一的 vpc 對等互連,則有一種更簡單的方法:

import boto.vpc
conn = boto.vpc.connect_to_region('us-east-1')
peering = conn.get_all_vpc_peering_connections()[0]
peering.id

暫無
暫無

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

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