是否可以使用boto API在s3中获取存储桶位置?
我在AWS API上讨论此功能 - http://docs.aws.amazon.com/AmazonS3/latest/API/RESTBucketGETlocation.html
提前致谢。
答案 0 :(得分:5)
您可以调用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
答案 1 :(得分:0)
对于boto3,您可以使用get_bucket_location方法,该方法将返回以下其中一项(截至2019年11月):
'EU'|'eu-west-1'|'us-west-1'|'us-west-2'|'ap-south-1'|'ap-southeast-1'|'ap-东南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']