Using Botto To Run and Manage Amazon AMI Instances
From Resin 3.0
Using boto to fire up three Resin AMI instances.
ami-bb16ddd2 is an AMI which has Resin 4.24 on it.
from boto.ec2.connection import EC2Connection
import time
conn = EC2Connection('AWS_ACCESS_KEY', 'AWS_SECRET_KEY')
resin_image = conn.get_all_images(image_ids=["ami-bb16ddd2"])[0]
reservation = resin_image.run( min_count=3, max_count=3,
user_data="blah blah blah",
instance_type='t1.micro',
key_name="resin2")
instances = reservation.instances
time.sleep(20)
count = 0
done = 0
while True:
count += 1
if count > 10: break
print "Checking servers..."
for instance in instances:
done=0
instance.update()
print "Server status %s " % instance.state
if instance.state==u'running': done+=1
if done >= 3: break
time.sleep(20)
print ("All instances are running")
# TODO read ~/.eucarc file for variables for AWS_ACCESS_KEY, AWS_SECRET_KEY # TODO Allow passing of ami-bb16ddd2 as command line. # TODO read USER_DATA from file passed as command line arg # TODO pass number of servers as command line arg