#!/usr/bin/env python

import os
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

ACCESS_ID = os.getenv('AWSAccessKeyId')
SECRET_KEY = os.getenv('AWSSecretKey')

IMAGE_ID = 'ami-34ddbe5c'
SIZE_ID = 't2.micro'

cls = get_driver(Provider.EC2_US_EAST)
driver = cls(ACCESS_ID, SECRET_KEY)

sizes = driver.list_sizes()
images = driver.list_images()

size = [s for s in sizes if s.id == SIZE_ID][0]
image = [i for i in images if i.id == IMAGE_ID][0]

#Reads cloud config file
userdata = "\n".join(open('./cloud.cfg').readlines())

#Replace the name of the ssh key pair with yours
#You will need to open SSH port 22 on your default security group
name = "ecs"
nodes = driver.create_node(name=name, image=image,size=size, ex_keyname='ecs', ex_mincount=5, ex_maxcount=5, ex_iamprofile='cookbook', ex_userdata=userdata)
print nodes
snap, ip = driver.wait_until_running(nodes=nodes)[0]
print ip

249059b8a07ab935e73aa3998c268ddac3116253
#!/usr/bin/env python

import os
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

ACCESS_ID = os.getenv('AWSAccessKeyId')
SECRET_KEY = os.getenv('AWSSecretKey')

IMAGE_ID = 'ami-34ddbe5c'
SIZE_ID = 't2.micro'

cls = get_driver(Provider.EC2_US_EAST)
driver = cls(ACCESS_ID, SECRET_KEY)

sizes = driver.list_sizes()
images = driver.list_images()

size = [s for s in sizes if s.id == SIZE_ID][0]
image = [i for i in images if i.id == IMAGE_ID][0]

#Reads cloud config file
userdata = "\n".join(open('./cloud.cfg').readlines())

#Replace the name of the ssh key pair with yours
#You will need to open SSH port 22 on your default security group
name = "ecs"
nodes = driver.create_node(name=name, image=image,size=size, ex_keyname='ecs', ex_mincount=5, ex_maxcount=5, ex_iamprofile='cookbook', ex_userdata=userdata)
print nodes
snap, ip = driver.wait_until_running(nodes=nodes)[0]
print ip
