All Products
Search
Document Center

Object Storage Service:Delete a bucket (Node.js SDK)

Last Updated:Nov 29, 2025

A bucket is a container that stores objects. This topic describes how to delete a bucket.

Note
  • Before deleting a bucket, delete all files, LiveChannels, and fragments from multipart uploads in the bucket.

  • If the bucket has incomplete multipart uploads, use listUploads and abortMultipartUpload to cancel the uploads before you can delete the bucket.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM Policy or Bucket policies.

API

Action

Definition

DeleteBucket

oss:DeleteBucket

Deletes a bucket.

Sample code

The following code provides an example of how to delete a specified bucket.

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

const client = new OSS({
  // Set region to the region where the bucket is located. For example, if the bucket is in the China (Hangzhou) region, set region to oss-cn-hangzhou.
  region: 'yourregion',
  // Obtain access credentials from environment variables. Before you run the sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Set bucket to the name of your bucket.
  bucket: 'yourBucketName',
});

async function deleteBucket() {
  try {
    // Specify the bucket name.
    const result = await client.deleteBucket('yourbucketname');
    console.log(result);
  } catch (err) {
    console.log(err);
  }
}

deleteBucket();

References

  • For the complete sample code used to delete a bucket, see GitHub sample.

  • For more information about the API operation to delete a bucket, see DeleteBucket.