All Products
Document Center

Query the regions of buckets

Last Updated: May 19, 2022

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.

Sample code

The following code provides an example on how to query the region or location of a bucket:

using Aliyun.OSS;
using Aliyun.OSS.Common;
// 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 
var endpoint = "";
// 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. 
var accessKeyId = "yourAccessKeyId";
var accessKeySecret = "yourAccessKeySecret";
// Set yourBucketName to the name of the bucket. 
var bucketName = "yourBucketName";

// Create an OSSClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
    // Query the region of the bucket. 
    var result = client.GetBucketLocation(bucketName);
    Console.WriteLine("Get bucket:{0} Info succeeded ", bucketName);
    Console.WriteLine("bucket Location: {0}", result.Location);
catch (OssException ex)
    Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
        ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);


For more information about the API operation that you can call to query the region of a bucket, see GetBucketLocation.