Magnus
Magnus

Reputation: 73

fetch vpc peering connection id in boto

I wish to retrieve the vpc peering connection id in boto, something that would be done by "aws ec2 describe-vpc-peering-connections". I couldn't locate its boto equivalent. Is it possible to retrieve it in boto ?

Upvotes: 1

Views: 1898

Answers (3)

CICD
CICD

Reputation: 23

boto3 is different from the previous boto. Here is the solution in boto3:

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

Upvotes: 3

BMW
BMW

Reputation: 45333

Get all vpc peering IDs

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

If you know the accepter VPC id and requester vpc ID, you should get the vpc peering id by this way:

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

If that's the only vpc peering in your environment, an easier way:

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

Upvotes: 0

garnaat
garnaat

Reputation: 45916

In boto you would use boto.vpc.get_all_peering_connections(), as in:

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)

Upvotes: 0

Related Questions