Skip to content

Instantly share code, notes, and snippets.

@sunglassatnight
Created January 27, 2014 19:37
Show Gist options
  • Save sunglassatnight/8655771 to your computer and use it in GitHub Desktop.
Save sunglassatnight/8655771 to your computer and use it in GitHub Desktop.
fab
from fabric.api import *
import boto.ec2
from clom import clom
def create_vm():
conn = boto.ec2.connect_to_region(
'us-west-2',
aws_access_key_id='AKIAJAJ7JAFYVAYKDXPA',
aws_secret_access_key='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')
conn.run_instances(
'ami-c6cc43f6',
key_name='logan',
instance_type='m1.small',
security_groups=['launch-wizard-1'])
reservations = conn.get_all_reservations()
instances = reservations[-1].instances
inst = instances[0]
print 'The ip address is: %s' % inst.ip_address
print 'The default username is "ubuntu"'
@jong
Copy link

jong commented Jan 27, 2014

on line 12, the run_instances call will return the reservation it created. You should save this into a variable and then just use the instances property. This will also eliminate the need to make the get_all_reservations call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment