我希望在boto中检索vpc对等连接ID,这可以通过“aws ec2 describe-vpc-peering-connections”来完成。我找不到它的boto等价物。是否可以用boto检索它?
答案 0 :(得分:1)
boto3与以前的boto不同。这是boto3中的解决方案:
import boto3
prevar = boto3.client('ec2')
var1 = prevar.describe_vpc_peering_connections()
print(var1)
答案 1 :(得分:0)
在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)
答案 2 :(得分:0)
获取所有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
如果您知道accepter VPC id和requester 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