Using Botto To Run and Manage Amazon AMI Instances

From Resin 3.0

Jump to: navigation, search

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 = min_count=3, max_count=3,
                               user_data="blah blah blah", 

instances = reservation.instances

count = 0
done = 0
while True:
    count += 1
    if count > 10: break
    print "Checking servers..."
    for instance in instances:
        print "Server status %s " % instance.state
        if instance.state==u'running': done+=1
    if done >= 3: break

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
Personal tools