Skip to content

Instantly share code, notes, and snippets.

@dirkk0
Created October 17, 2012 06:44
Show Gist options
  • Select an option

  • Save dirkk0/3904066 to your computer and use it in GitHub Desktop.

Select an option

Save dirkk0/3904066 to your computer and use it in GitHub Desktop.
minimal Amazon EC2 startup script in boto/python
import time
from boto import ec2
it = 't1.micro'
# it = 'm1.small'
ami = "ami-137bcf7a" # ubuntu 12.04
instance_name = "myInstance"
security_group = "quicklaunch-0"
# elastic_ip = "1.2.3.4"
ec2c = ec2.connection.EC2Connection('AWS_ACCESS_KEY_ID','AWS_SECRET_ACCESS_KEY')
user_data = """
wont work on ubuntu
"""
r = ec2c.run_instances(ami, instance_type=it, key_name=keypair, user_data=user_data, security_groups=[security_group])
time.sleep(5)
i = r.instances[-1]
ec2c.create_tags([i.id], {"Name": instance_name})
print "waiting for AMI to start ..."
while not i.update() == 'running':
print ".",
time.sleep(2)
print " ... success!"
print i.ip_address
# print "associated elastic IP?"
# print ec2c.associate_address(i.id, elastic_ip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment