All Products
Search
Document Center

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

Last Updated:Mar 20, 2026

A bucket is a container that stores objects. Delete a bucket when it is no longer needed. Before deletion, you must empty the bucket of all objects, LiveChannels, and incomplete multipart uploads.

Prerequisites

Before you begin, ensure that you have:

  • Emptied the bucket of all objects, LiveChannels, and parts from incomplete multipart uploads. To cancel incomplete multipart uploads, use listUploads and abortMultipartUpload

  • Granted the oss:DeleteBucket permission to your Alibaba Cloud account or RAM user through a RAM policy or bucket policy

Note

Alibaba Cloud accounts have full permissions by default. RAM users and RAM roles have no permissions by default and require explicit grants.

Permissions

APIActionDescription
DeleteBucketoss:DeleteBucketDeletes a bucket

Delete a bucket

The following example deletes a specified bucket.

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

const client = new OSS({
  // Set region to the region where the bucket is located.
  // Example: oss-cn-hangzhou for the China (Hangzhou) region.
  region: 'oss-cn-hangzhou',
  // Load credentials from environment variables.
  // Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  bucket: 'examplebucket',
});

async function deleteBucket() {
  try {
    const result = await client.deleteBucket('examplebucket');
    console.log('Bucket deleted successfully:', result);
  } catch (err) {
    console.log(err);
  }
}

deleteBucket();

Replace the following placeholders with actual values:

PlaceholderDescriptionExample
oss-cn-hangzhouThe region where the bucket is locatedoss-ap-southeast-1
examplebucketThe name of the bucket to deletemy-project-bucket

Troubleshooting

If bucket deletion fails, check the following:

  • Bucket is not empty: Delete all objects, LiveChannels, and parts from incomplete multipart uploads. Use listUploads to list incomplete multipart uploads and abortMultipartUpload to cancel them.

  • Insufficient permissions: Make sure the oss:DeleteBucket action is granted in the RAM policy or bucket policy.

What's next