All Products
Search
Document Center

Object Storage Service:Query the region of a bucket

Last Updated:Oct 18, 2023

A bucket is a container used to store objects in Object Storage Service (OSS). All objects in OSS are contained in buckets. 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,
  // Specify the name of the 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.