Skip to content

Instantly share code, notes, and snippets.

@wehappyfew
Last active August 29, 2015 14:17
Show Gist options
  • Save wehappyfew/80ad76acba893e9914f1 to your computer and use it in GitHub Desktop.
Save wehappyfew/80ad76acba893e9914f1 to your computer and use it in GitHub Desktop.
import boto, boto.ec2, time
# creds for AWS user
aws_access_key_id = "sdvsdvsdvsdvsdvsdv"
aws_secret_access_key = "sdvsdvsdvsdvsdvsdvsdv"
Windows_Server_2003_R2_Base_64bit_imageID = "ami-b9f2d789"
Ubuntu_Server_14_04_LTS_imageID = "ami-23ebb513"
AMIs = {
"Oregon" : "ami-1111111", # us-west-2
"Virginia" : "ami-2222222" # us-east-1
}
def create_instances(region , img_id, instance_num, inst_type, sec_groups, key_pair_name, avail_zone, mock_run=True):
# make the connection to AWS with my creds
conn = boto.ec2.connect_to_region( region_name = region, # eg us-east-1
aws_access_key_id = aws_access_key_id,
aws_secret_access_key = aws_secret_access_key,
)
#
reservations = conn.run_instances(
max_count = instance_num, # number of instances to launch
dry_run = mock_run, # check launch request but dont do it!
image_id = img_id, # the AMI id to launch from
instance_type = inst_type,
security_groups = sec_groups, # must be list
key_name = key_pair_name,
placement = avail_zone # the availability zone within the region
)
return conn,reservations
create_instances(region="us-east-1", img_id=AMIs["Virginia"], instance_num=1, inst_type="t2.micro",key_pair_name="keyname", mock_run=False)
create_instances(region="us-west-2", img_id=AMIs["Oregon"], instance_num=1 , inst_type="t2.micro", key_pair_name="keyname", mock_run=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment