博托获得s3桶位置

7 python boto amazon-web-services

是否可以使用boto API在s3中获取存储桶位置?

我正在谈论AWS API中的这个功能 - http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETlocation.html

提前致谢.

Pad*_*dez 6

您可以调用get_location()方法:

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)
Run Code Online (Sandbox Code Playgroud)

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


eat*_*ood 5

对于 boto3,您可以使用 get_bucket_location 方法,该方法将返回以下之一(截至 2019 年 11 月):

'欧盟'|'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'

一个示例方法是这样的:

def get_location(client, bucket_name):
    response = client.get_bucket_location(Bucket=bucket_name)
    return response['LocationConstraint']
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅文档