How to detach and delete Internet gateway from a VPC using boto3?

0 votes
How to detach and delete Internet gateway from a VPC using boto3?
Dec 4, 2018 in AWS by Kanishk
• 850 points
107 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Here is a simple implementation. You need to keep few things in mind and some prerequisite.

You need to detach the ig from your VPC.

You need to have the ig-id and the vpc-id to continue.

import boto3
ec2 = boto3.resource('ec2')
vpc = ec2.Vpc('vpc-id')
gw = ec2.InternetGateway('igw-id')
vpc.detach_internet_gateway(InternetGatewayId = 'igw-id')
gw.delete()

Hope this helps.

answered Dec 4, 2018 by Shuvodip Ghosh

Related Questions In AWS

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
101 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
262 views
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,120 points
24 views
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
33 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
171 views
0 votes
1 answer

Unable to delete subnets in a VPC using boto3.

.terminate is used for instances and not ...READ MORE

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

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.