Skip to content

Instantly share code, notes, and snippets.

@slackorama
Created August 1, 2012 06:16
Show Gist options
  • Save slackorama/3224213 to your computer and use it in GitHub Desktop.
Save slackorama/3224213 to your computer and use it in GitHub Desktop.
Boto and ec2
import boto
ec2 = boto.connect_ec2()
key_pair = ec2.create_key_pair('ec2-sample-key') # only needs to be done once
key_pair.save('/Users/patrick/.ssh')
reservation = ec2.run_instances(image_id='ami-bb709dd2', key_name='ec2-sample-key')
# Wait a minute or two while it boots
for r in ec2.get_all_instances():
if r.id == reservation.id:
break
print r.instances[0].public_dns_name # output: ec2-184-73-24-97.compute-1.amazonaws.com
$ chmod 600 ~/.ssh/ec2-sample-key.pem
$ ssh -i ~/.ssh/ec2-sample-key.pem ubuntu@ec2-184-73-24-97.compute-1.amazonaws.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment