Skip to content

Instantly share code, notes, and snippets.

@iogi
Created May 6, 2014 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iogi/01f77d9a4959ac1b88f4 to your computer and use it in GitHub Desktop.
Save iogi/01f77d9a4959ac1b88f4 to your computer and use it in GitHub Desktop.
import boto.ec2
VPC_ID = 'vpc-xxxxxxxx'
conn = boto.ec2.connect_to_region(
'ap-northeast-1',
aws_access_key_id='<access key>',
aws_secret_access_key='<secret access>')
sg_elb = conn.create_security_group('elb2', '80,443 from world', VPC_ID)
sg_elb.authorize('tcp', 80, 80, '0.0.0.0/0')
sg_elb.authorize('tcp', 4443, 443, '0.0.0.0/0')
sg_web = conn.create_security_group('web2', 'from elb 80', VPC_ID)
sg_web.authorize('tcp', 80, 80, src_group=sg_elb)
sg_admin = conn.create_security_group('admin2', 'ssh from office', VPC_ID)
sg_admin.authorize('tcp', 22, 22, ['192.168.0.0/24', '10.11.12.13/32'])
sg_db = conn.create_security_group('db2', 'from web and admin', VPC_ID)
sg_db.authorize('tcp', 3306, 3306, src_group=sg_elb)
sg_db.authorize('tcp', 3306, 3306, src_group=sg_admin)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment