Skip to content

Instantly share code, notes, and snippets.

@masayang
Created December 7, 2012 00:27
Show Gist options
  • Save masayang/4229688 to your computer and use it in GitHub Desktop.
Save masayang/4229688 to your computer and use it in GitHub Desktop.
VPC w/ public subnet
#! /usr/bin/env python
from boto.vpc import VPCConnection
from boto.ec2 import get_region
EC2_REGION='ap-northeast-1'
VPC_CIDR='10.99.0.0/16'
PUBLIC_CIDR='10.99.0.0/24'
ec2region = get_region(EC2_REGION)
conn = VPCConnection(region=ec2region)
vpc = conn.create_vpc(VPC_CIDR)
igw = conn.create_internet_gateway()
conn.attach_internet_gateway(igw.id, vpc.id)
subnet = conn.create_subnet(vpc.id, PUBLIC_CIDR)
route_table = conn.get_all_route_tables(
filters=[("vpc-id", vpc.id)])[0]
conn.create_route(route_table.id, '0.0.0.0/0', gateway_id=igw.id)
print "vpc-id %s created" % vpc.id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment