Use the location
parameter to the
create_bucket
method to specify the location of the new
bucket.
Originally, there was just a single S3 endpoint and all data was stored in one region or location, the eastern United States. Over time, however, the S3 service has expanded, and there are now five region-specific endpoints:
US Standard
US-West (Northern California)
EU (Ireland)
Asia Pacific (Singapore)
Asia Pacific (Japan)
There is a big difference, however, in the way S3 handles
resources and regions. For services like EC2, SimpleDB, SQS, and the
like, the regions are treated as completely separate services, and
resources cannot be easily shared across these regions. For example, if
you want to create an EC2 instance in the EU region, you have to connect
to the EC2 EU endpoint to do so, and that instance is unknown to the
other EC2 regions. With S3, you specify a Location
for the
bucket when it is created, but once it is created, you can access the
bucket from any of the S3 endpoints. In addition, you can create an EU
bucket when you are talking to the US endpoint and vice versa. So, the
resource namespace is global to the entire S3 service, across all
regions. The main reason you might decide to talk to a region-specific
endpoint is to get better latency in your connections.
Example 3-2. Create a Bucket in a Specific Location
import boto from boto.s3.connection import Location def create_bucket(bucket_name, location=Location.DEFAULT): """ Create a bucket. If the bucket already exists and you have access to it, no error will be returned by AWS. Note that bucket names are global to a S3 region or location so you need to choose a unique name. bucket_name - The name of the bucket to be created. location - The location in which the bucket should be created. The Location class is a simple enum-like static class that has the following attributes: DEFAULT|EU|USWest|APNortheast|APSoutheast """ s3 = boto.connect_s3() # First let's see if we already have a bucket of this name. # The lookup method will return a Bucket object if the # bucket exists and we have access to it or None. bucket = s3.lookup(bucket_name) if bucket: print 'Bucket (%s) already exists' % bucket_name else: # Let's try to create the bucket. This will fail if # the bucket has already been created by someone else. try: bucket = s3.create_bucket(bucket_name, location=location) except s3.provider.storage_create_error, e: print 'Bucket (%s) is owned by another user' % bucket_name return bucket