Scooby
Scooby

Reputation: 3581

AWS-BOTO security group error

I have the following code to spin up new instances:

conn = boto.ec2.connect_to_region("us-east-1", security_token = "xx", aws_access_key_id= "xx",  aws_secret_access_key= "xx")


security_groups = conn.get_all_security_groups()
for security_group in security_groups:
    if str(security_group)[14:] == "xx":
        conn.run_instances(
                'ami-da2cd5b2',
                key_name='fornax_keypair',
                instance_type='c1.xlarge',
                security_groups=security_group)
    else:
        continue

It finds the security group and then gives the error :

TypeError: 'SecurityGroup' object is not iterable

If I change it to str(security_group), it then gives the error:

<Response><Errors><Error><Code>InvalidGroup.NotFound</Code><Message>The security groups 'f', 'g', 'd', 'e', 'c', 'n', 'o', 'j', '.', 'i', 'v', 'u', 't', 's', 'r', 'p', '
:', 'y' do not exist</Message></Error></Errors><RequestID>c96afd3c-de3f-4441-be65-c6a85fbe7868</RequestID></Response>

Also how do I attach the connection to an already established vpc connection and subnet ?

Upvotes: 0

Views: 751

Answers (1)

garnaat
garnaat

Reputation: 45856

The security_groups parameter to run_instances is supposed to be list of security group names. You are passing a scalar string value. Try this instead:

conn.run_instances(
    'ami-da2cd5b2',
    key_name='fornax_keypair,
    instance_type='c1.xlarge',
    security_groups=[security_group])

Upvotes: 1

Related Questions