Boto get s3 bucket location

For boto3, you can use the get_bucket_location method, which will return to you one of the following (as of November 2019):

'EU'|'eu-west-1'|'us-west-1'|'us-west-2'|'ap-south-1'|'ap-southeast-1'|'ap-southeast-2'|'ap-northeast-1'|'sa-east-1'|'cn-north-1'|'eu-central-1'

A sample method would be something like this:

def get_location(client, bucket_name):
    response = client.get_bucket_location(Bucket=bucket_name)
    return response['LocationConstraint']

See the documentation for more info.


You can call the get_location() method:

conn = boto.connect_s3()
bucket = conn.get_bucket(bucket_name)
bucket_location = bucket.get_location()
if bucket_location:
    conn = boto.s3.connect_to_region(bucket_location)
    bucket = conn.get_bucket(bucket_name)

http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.bucket.Bucket.get_location