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 create a bucket.

Sample code

The following code provides an example on how to create a bucket named examplebucket:

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

const client = new OSS({
  // Set yourregion to 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 OSS because the account has permissions on all API operations. We recommend that you use a 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'
});

// Create the bucket. 
async function putBucket() {
  try {
    const options = {
      storageClass: 'Standard', // By default, the storage class of a bucket is Standard. To set the storage class of the bucket to Archive, set storageClass to Archive. 
      acl: 'private', // By default, the ACL of a bucket is private. To set the ACL of the bucket to public read, set acl to public-read. 
      dataRedundancyType: 'LRS' // By default, the data redundancy type of a bucket is locally redundant storage (LRS). To set the data redundancy type of the bucket to zone-redundant storage (ZRS), set dataRedundancyType to ZRS. 
    }
    // Specify the bucket name. 
    const result = await client.putBucket('examplebucket', options);
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

putBucket();        

References

For more information about the API operation that you can call to create a bucket, see PutBucket.