How to create subnets in a vpc using boto3

0 votes
How to create subnets in a vpc using boto3?
Dec 5, 2018 in AWS by Kanishk
• 890 points
4,616 views

1 answer to this question.

0 votes

Here is the simple way of implementing the code for creating a vpc and also subnets inside it.

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)
subnet = ec2.create_subnet(CidrBlock = '10.0.2.0/24', VpcId= vpc.id)
print(subnet.id)

Hope this will help

answered Dec 5, 2018 by Shuvodip Ghosh

Related Questions In AWS

0 votes
1 answer

How to create a VPC in AWS using Boto3?

Hi@akhtar, Amazon Web Services enables you to create ...READ MORE

answered Oct 9, 2020 in AWS by MD
• 95,460 points
1,675 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 5, 2018 in AWS by Shuvodip Ghosh
890 views
0 votes
1 answer

How to create subnets in a VPC in AWS Console?

To create a subnet inside a VPC ...READ MORE

answered Feb 11, 2019 in AWS by Priyaj
• 58,020 points
1,075 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
1,222 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 5, 2018 in AWS by Shuvodip Ghosh
1,827 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP