Tampa
Tampa

Reputation: 78382

Python and boto with autoscaling -- How to connect to a region

How do I connect a connection object to a region? I can create a connection. I can connect to a region. How do I link a connection object to a region

region = 'ap-southeast-2'
conn = AutoScaleConnection(aws_access_key_id, aws_secret_access_key)
autoscale = boto.ec2.autoscale.connect_to_region(region)

Upvotes: 0

Views: 1421

Answers (2)

garnaat
garnaat

Reputation: 45906

The method connect_to_region appears in every boto module and is the best way to create a connection to a service. The method, in this case, returns an AutoScaleConnection object so there is no need to try to create the connection object directly. So, something like this will work:

import boto.ec2.autoscale
region = 'ap-southeast-2'
conn = boto.ec2.autoscale.connect_to_region(region, aws_access_key_id="<access_key", aws_secret_access_key="<secret_key>")
mygroups = conn.get_all_groups()
...

Upvotes: 3

Sirex
Sirex

Reputation: 219

I couldn't get garnaat's solution to work for me, but this worked:

regionObj = [region for region in boto.ec2.autoscale.regions() if region.name == 'ap-southeast-2'][0]
as_conn = AutoScaleConnection(api_key, api_secret_key, region=regionObj)
mygroups = as_conn.get_all_groups()

Upvotes: 0

Related Questions