Skip to content

Instantly share code, notes, and snippets.

@cpatrick
Last active December 11, 2015 05:39
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 cpatrick/4553990 to your computer and use it in GitHub Desktop.
Save cpatrick/4553990 to your computer and use it in GitHub Desktop.
Setting up a basic EC2 Instance with boto
from boto.ec2.connection import EC2Connection
import secretkeys
conn = EC2Connection(secretkeys.AWS_ACCESS_KEY, secretkeys.AWS_SECRET_KEY)
security_description = 'Security rules for external servers'
repo_sg = conn.create_security_group('external-server', security_description)
repo_sg.authorize('tcp', 80, 80, '0.0.0.0/0')
repo_sg.authorize('tcp', 22, 22, '0.0.0.0/0')
repo_sg.authorize('tcp', 443, 443, '0.0.0.0/0')
reservation = conn.run_instances(image_id='ami-fd20ad94', # from canonical
key_name='canepi',
security_groups=['external-server'],
instance_type='t1.micro')
intance = reservation.instances[0]
instance.start()
# wait a bit
instance.update()
print instance.public_dns_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment