All Products
Document Center

Object Storage Service:Query bucket information

Last Updated:Jul 05, 2022

A bucket is a container used to store objects in Object Storage Service (OSS). All objects in OSS are contained in buckets. This topic describes how to query the information about a bucket.

Sample code

The following code provides an example on how to query the information about a bucket, including the region, creation date, and access control list (ACL) of the 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 = "yourEndpoint";
// The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. 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 your bucket. 
var bucketName = "yourbucketname";

// Create an OSSClient instance. 
var client = new OssClient(endpoint, accessKeyId, accessKeySecret);
    // Information about a bucket includes the region (Region or Location), creation date (CreationDate), owner (Owner), and ACL (Grants) of the bucket. 
    var bucketInfo = client.GetBucketInfo(bucketName);
    Console.WriteLine("Get bucket:{0} Info succeeded ", bucketName);
    // Query the region of the bucket. 
    Console.WriteLine("bucketInfo Location: {0}", bucketInfo.Bucket.Location);
    // Query the creation date of the bucket. 
    Console.WriteLine("bucketInfo CreationDate: {0}", bucketInfo.Bucket.CreationDate);
    // Query the type of disaster recovery of a bucket. 
    Console.WriteLine("bucketInfo DataRedundancyType: {0}", bucketInfo.Bucket.DataRedundancyType);
    // Query the ACL information of the bucket. 
    Console.WriteLine("bucketInfo Grant: {0}", bucketInfo.Bucket.AccessControlList.Grant);
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 information about a bucket, see GetBucketInfo.