How to attach a internet gateway with a VPC using Python boto3?

0 votes
How to attach a internet gateway with a VPC using Python boto3?
Dec 4, 2018 in AWS by Kanishk
• 880 points
258 views

1 answer to this question.

0 votes

Here is the code to attach a internet gateway to your vpc. 

Here I am creating a new VPC and internet gateway and attaching it to the created VPC.

import boto3
ec2 = boto3.resource('ec2')
vpc = ec2.create_vpc(CidrBlock='10.0.0.0/16')
vpc.create_tags(Tags=[{"Key":"TestVPC","Value":"default_vpc"}])
vpc.wait_until_available()
print(vpc.id)
ig = ec2.create_internet_gateway()
vpc.attach_internet_gateway(InternetGatewayId = ig.id)
print(ig.id)

Hope this helps.

answered Dec 4, 2018 by Shuvodip Ghosh

Related Questions In AWS

0 votes
1 answer

How to attach an Internet Gateway to a VPC?

To attach an Internet Gateway to a ...READ MORE

answered Feb 21 in AWS by Priyaj
• 56,160 points
30 views
0 votes
1 answer

How to create subnets in a vpc using boto3?

Here is the simple way of implementing ...READ MORE

answered Dec 4, 2018 in AWS by Shuvodip Ghosh
348 views
0 votes
1 answer

How to delete all the subnets from a VPC using boto3?

You can refer to this question here: https://www.edureka.co/community/32182/unable-to-delete-subnets-in-a-vpc-using-boto3 You ...READ MORE

answered Dec 4, 2018 in AWS by Shuvodip Ghosh
136 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Getting error while deleting my VPC.

This is the code to delete the ...READ MORE

answered Dec 4, 2018 in AWS by Shuvodip Ghosh
47 views
0 votes
1 answer

How to delete a VPC using boto3?

You can view this answer here : https://www.edureka.co/community/32160/getting-error-while-deleting-my-vpc Before ...READ MORE

answered Dec 4, 2018 in AWS by Shuvodip Ghosh
228 views