All Products
Document Center

Object Storage Service:Query bucket information

Last Updated:Oct 18, 2023

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

Sample code

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

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

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that you have configured environment variables OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET. 
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET

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. 
  // Query the name of the bucket. 
  // Query the ID of the bucket owner. 
  // Query the name of the bucket owner. The name 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 status of the bucket. 



  • For the complete sample code that is used to query information about a bucket, visit GitHub.

  • For more information about the API operation that you can call to query information about a bucket, see GetBucketInfo.