Python Boto: How to specify Subnet ID And Security Group?

I am trying to curse an instance using boto. The instance must be running on a specific subnet in my VPC, as well as in a specific security group in my vpc.

The following code successfully starts an instance in my VPC on the correct subnet:

conn.run_instances( image_id=base_ami, key_name=bakery_key, subnet_id=bakery_subnet) 

The following code gives me the following error:

 reservation = conn.run_instances( image_id=base_ami, key_name=bakery_key, security_groups=['TheNameOfMySecurityGroup'], subnet_id=bakery_subnet) 

Here is the error I am getting. I get the same error when I specify the use of a subnet identifier instead of the actual subnet name:

 Traceback (most recent call last): File "./botobakery.py", line 24, in <module> subnet_id=bakery_subnet) File "/usr/lib/python2.6/site-packages/boto/ec2/connection.py", line 935, in run_instances verb='POST') File "/usr/lib/python2.6/site-packages/boto/connection.py", line 1177, in get_object raise self.ResponseError(response.status, response.reason, body) boto.exception.EC2ResponseError: EC2ResponseError: 400 Bad Request <?xml version="1.0" encoding="UTF-8"?> <Response><Errors><Error><Code>InvalidParameterCombination</Code><Message>The parameter groupName cannot be used with the parameter subnet</Message></Error></Errors> <RequestID>c8a6b824-4ab3-41d2-9633-9830c167d2d6</RequestID></Response> 

I would be extremely grateful and grateful if anyone knows how to run my instance on my specific subnet AND my special security group

+8
python amazon-web-services amazon-ec2 boto
source share
1 answer

Since you are running VPC, you must specify security groups by their identifier, not by name. Names are valid only in the "classic" EC2. So, if the security group has the identifier sg-12345678 , you can use the following command:

 reservation = conn.run_instances( image_id=base_ami, key_name=bakery_key, security_group_ids=['sg-12345678'], subnet_id=bakery_subnet) 
+10
source share

All Articles