How to create subnets in a vpc using boto3?

0 votes
How to create subnets in a vpc using boto3?
Dec 4, 2018 in AWS by Kanishk
• 880 points
681 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 4, 2018 by Shuvodip Ghosh

Related Questions In AWS

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
146 views
0 votes
1 answer
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
84 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
259 views