All Products
Search
Document Center

Object Storage Service:Query the region of a bucket

Last Updated:Nov 05, 2024

A bucket is a container that is used to store objects in Object Storage Service (OSS). Every object is contained in a bucket. This topic describes how to query the region of a bucket.

Sample code

The following sample code shows how to query the region or location of a bucket:

const OSS = require('ali-oss')
const client = new OSS({  
  // 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,
  authorizationV4: true,
  // Specify the name of your bucket.
  bucket: 'yourBucketName','
});

async function getLocation() {
  try {
    const result = await client.getBucketInfo();
    console.log(result.bucket.Location);
  } catch (e) {
    console.log(e);
  }
}

getLocation();

References

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

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