Question

What I'm trying to do, is not have to manually create new EC2 instances as needed through the AWS.Amazon.com site, but rather programtically start up new instances based off a ami using python's boto module

import boto.ec2
conn = boto.ec2.connect_to_region("us-west-2",
    aws_access_key_id='<aws access key>',
    aws_secret_access_key='<aws secret key>')

#how to now spin up new instances based off a snapshot (already) preconfigured on ec2?

As in my comment, I'm trying to startup new instances based off a specific given ami id?

I can't seem to find a good way to do this. Can anyone help here?

Thank you

Was it helpful?

Solution

From the documentation:

Possibly, the most important and common task you’ll use EC2 for is to launch, stop and terminate instances. In its most primitive form, you can launch an instance as follows:

conn.run_instances('<ami-image-id>') 

This will launch an instance in the specified region with the default parameters. You will not be able to SSH into this machine, as it doesn’t have a security group set. See EC2 Security Groups for details on creating one.

Now, let’s say that you already have a key pair, want a specific type of instance, and you have your security group all setup. In this case we can use the keyword arguments to accomplish that:

conn.run_instances(
    '<ami-image-id>',
    key_name='myKey',
    instance_type='c1.xlarge',
    security_groups=['your-security-group-here'])

The <ami-image-id> is where you fill in your ami id.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top