Boto获取s3存储桶位置

问题描述 投票:5回答:2

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

我正在从AWS API讨论此功能-http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETlocation.html

提前感谢。

python amazon-web-services boto
2个回答
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)

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


0
投票

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

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

示例方法将是这样的:

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

请参见documentation for more info

© www.soinside.com 2019 - 2024. All rights reserved.