A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to query information about a bucket.

The following code provides an example on how to query information about a bucket, including the region, storage class, and versioning state.

const OSS = require('ali-oss')
const client = new OSS({
   // The endpoint of the China (Hangzhou) region is used in this example. Specify the actual endpoint.
  region: '<Your region>'
  // Security risks may arise if you use the AccessKey pair of an Alibaba Cloud account to log on to OSS because the account has permissions on all API operations. We recommend that you use your RAM user's credentials to call API operations or perform routine operations and maintenance. To create a RAM user, log on to the RAM console.
  accessKeyId: '<Your AccessKeyId>',
  accessKeySecret: '<Your AccessKeySecret>',
  bucket: '<Your bucket name>'

async function getBucketInfo() {
  const result = await client.getBucketInfo('<Your bucket>')
  // Query the region of the bucket.
  // Query the name of the bucket.
  // Query the ID of the bucket owner.
  // Query the name of the bucket owner, which is currently the same as the ID of the bucket owner.
  // Query the creation time of the bucket.
  // Query the storage class of the bucket.
  // Query the versioning state of the bucket.


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