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 information about a bucket.

The following code provides an example on how to query the information about a bucket, including the region and creation date of the bucket:

// Set yourEndpoint to the endpoint of the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set yourEndpoint to https://oss-cn-hangzhou.aliyuncs.com. 
String endpoint = "yourEndpoint";
// 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 Resource Access Management (RAM) user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
String accessKeyId = "yourAccessKeyId";
String accessKeySecret = "yourAccessKeySecret";

// Create an OSSClient instance. 
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

// Information about a bucket includes the region (Region or Location), creation date (CreationDate), and owner (Owner) of the bucket. 
// Specify the name of the bucket. Example: examplebucket. 
BucketInfo info = ossClient.getBucketInfo("examplebucket");
// Query the region. 
// Query the creation date of the bucket. 
// Query the information about the owner of the bucket. 
// Query the redundancy option for the bucket. 

// Shut down the OSSClient instance. 

For more information about how to query bucket information, see GetBucketInfo.