Last active
December 11, 2015 05:39
-
-
Save cpatrick/4553990 to your computer and use it in GitHub Desktop.
Setting up a basic EC2 Instance with boto
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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