Finding Available Regions for AWS

By default, when you create a connection to the EC2 service in boto, it connects to the US-EAST-1 region. Originally, that was the only region available, but AWS has expanded its operations considerably and, at the time of this writing, EC2 was available in the following regions, each with its own endpoint:

boto provides a number of ways to find and connect to these regions. For example, the following will return a list of all RegionInfo objects for a given service (EC2 in this case). Each of those RegionInfo objects has a connect method, which will return a Connection object for that region:

$ python
Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto.ec2
>>> boto.ec2.regions()
[RegionInfo:eu-west-1, RegionInfo:us-east-1, RegionInfo:ap-northeast-1,
RegionInfo:us-west-1, RegionInfo:ap-southeast-1]
>>> eu_conn = _[0].connect()

If you have the name of the region you want to connect to, you can also use this approach:

$ python
Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34) 
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import boto.ec2
>>> eu_conn = boto.ec2.connect_to_region('eu-west-1')
>>>

Finally, if you would like to change the default region boto uses when creating an EC2 connection, you can do so by adding something like this to your boto config file:

[Boto]
ec2_region_name = eu-west-1

Once this has been added to your boto config file, when you call boto.connect_ec2 without any parameters you will get a connection to the eu-west-1 region.