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 named examplebucket, which includes the region, storage class, and versioning status of the bucket:

const OSS = require('ali-oss');

const client = new OSS({
  // Set yourRegion to the endpoint of the region in which the bucket is located. For example, if your bucket is located in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to access Object Storage Service (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. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret'
});

async function getBucketInfo() {
  // Specify the name of the bucket. Example: examplebucket.   
  const bucket = 'examplebucket'

  const result = await client.getBucketInfo(bucket)
  // Query the region of the bucket. 
  console.log(result.bucket.Location) 
  // Query the name of the bucket. 
  console.log(result.bucket.Name)
  // Query the ID of the bucket owner. 
  console.log(result.bucket.Owner.ID) 
  // Query the name of the bucket owner, which is currently the same as the ID of the bucket owner. 
  console.log(result.bucket.Owner.DisplayName)
  // Query the creation time of the bucket. 
  console.log(result.bucket.CreationDate)
  // Query the storage class of the bucket. 
  console.log(result.bucket.StorageClass)
  // Query the versioning status of the bucket. 
  console.log(result.bucket.Versioning)
}

getBucketInfo()

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