A bucket is a container for objects stored in Object Storage Service (OSS). Every object is contained in a bucket. This topic describes how to query the region of a bucket.
The following sample code shows how to query the region or location of a bucket:
# -*- coding: utf-8 -*- import oss2 # Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access OSS, because the account has permissions on all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. auth = oss2.Auth('yourAccessKeyId', 'yourAccessKeySecret') # Specify the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the endpoint to https://oss-cn-hangzhou.aliyuncs.com. # Set yourBucketName to the name of the bucket. bucket = oss2.Bucket(auth, 'https://oss-cn-hangzhou.aliyuncs.com', 'yourBucketName') # Obtain the region of the bucket. result = bucket.get_bucket_location() print('location: ' + result.location)