Create AWS VPC using python boto
#!/usr/bin/env python2
import boto.vpc
import boto.ec2
import time
REGION_NAME = 'ap-southeast-1'
conn = boto.vpc.connect_to_region(REGION_NAME)
# Create a VPC
vpc = conn.create_vpc('10.0.0.0/16')
print vpc
# Configure the VPC to support DNS resolution and hostname assignment
conn.modify_vpc_attribute(vpc.id, enable_dns_support=True)
conn.modify_vpc_attribute(vpc.id, enable_dns_hostnames=True)
# Create an Internet Gateway
gateway = conn.create_internet_gateway()
print gateway
# Attach the Internet Gateway to our VPC
conn.attach_internet_gateway(gateway.id, vpc.id)
# Create a Route Table
route_table = conn.create_route_table(vpc.id)
route_table1 = conn.create_route_table(vpc.id)
print route_table
# Create Subnet - /24 subnet
subnet1 = conn.create_subnet(vpc.id, '10.0.1.0/24',availability_zone='ap-southeast-1a')
subnet2 = conn.create_subnet(vpc.id, '10.0.2.0/24',availability_zone='ap-southeast-1b')
subnet3 = conn.create_subnet(vpc.id, '10.0.3.0/24',availability_zone='ap-southeast-1a')
subnet4 = conn.create_subnet(vpc.id, '10.0.4.0/24',availability_zone='ap-southeast-1b')
subnet5 = conn.create_subnet(vpc.id, '10.0.5.0/24',availability_zone='ap-southeast-1a')
subnet6 = conn.create_subnet(vpc.id, '10.0.6.0/24',availability_zone='ap-southeast-1b')
print subnet1
print subnet2
print subnet3
print subnet4
print subnet5
print subnet6
# Associate Route Table with our public subnet
route1=conn.associate_route_table(route_table.id, subnet1.id)
route2=conn.associate_route_table(route_table.id, subnet2.id)
print route1
print route2
# Associate Route Table with our private subnet
route3=conn.associate_route_table(route_table1.id, subnet3.id)
route4=conn.associate_route_table(route_table1.id, subnet4.id)
route5=conn.associate_route_table(route_table1.id, subnet5.id)
route6=conn.associate_route_table(route_table1.id, subnet6.id)
print route3
print route4
print route5
print route6
# Create a Route from our Internet Gateway to the internet
route = conn.create_route(route_table.id, '0.0.0.0/0', gateway.id)
print route
#!/usr/bin/env python2
import boto.vpc
import boto.ec2
import time
REGION_NAME = 'ap-southeast-1'
conn = boto.vpc.connect_to_region(REGION_NAME)
# Create a VPC
vpc = conn.create_vpc('10.0.0.0/16')
print vpc
# Configure the VPC to support DNS resolution and hostname assignment
conn.modify_vpc_attribute(vpc.id, enable_dns_support=True)
conn.modify_vpc_attribute(vpc.id, enable_dns_hostnames=True)
# Create an Internet Gateway
gateway = conn.create_internet_gateway()
print gateway
# Attach the Internet Gateway to our VPC
conn.attach_internet_gateway(gateway.id, vpc.id)
# Create a Route Table
route_table = conn.create_route_table(vpc.id)
route_table1 = conn.create_route_table(vpc.id)
print route_table
# Create Subnet - /24 subnet
subnet1 = conn.create_subnet(vpc.id, '10.0.1.0/24',availability_zone='ap-southeast-1a')
subnet2 = conn.create_subnet(vpc.id, '10.0.2.0/24',availability_zone='ap-southeast-1b')
subnet3 = conn.create_subnet(vpc.id, '10.0.3.0/24',availability_zone='ap-southeast-1a')
subnet4 = conn.create_subnet(vpc.id, '10.0.4.0/24',availability_zone='ap-southeast-1b')
subnet5 = conn.create_subnet(vpc.id, '10.0.5.0/24',availability_zone='ap-southeast-1a')
subnet6 = conn.create_subnet(vpc.id, '10.0.6.0/24',availability_zone='ap-southeast-1b')
print subnet1
print subnet2
print subnet3
print subnet4
print subnet5
print subnet6
# Associate Route Table with our public subnet
route1=conn.associate_route_table(route_table.id, subnet1.id)
route2=conn.associate_route_table(route_table.id, subnet2.id)
print route1
print route2
# Associate Route Table with our private subnet
route3=conn.associate_route_table(route_table1.id, subnet3.id)
route4=conn.associate_route_table(route_table1.id, subnet4.id)
route5=conn.associate_route_table(route_table1.id, subnet5.id)
route6=conn.associate_route_table(route_table1.id, subnet6.id)
print route3
print route4
print route5
print route6
# Create a Route from our Internet Gateway to the internet
route = conn.create_route(route_table.id, '0.0.0.0/0', gateway.id)
print route
Good Post
ReplyDelete