All Products
Search
Document Center

Object Storage Service:Delete a bucket (Ruby SDK)

Last Updated:Nov 29, 2025

You can delete a bucket when you no longer need it or want to stop billing for it. OSS charges are mainly for resources within a bucket. Before you can delete a bucket, you must clear all its resources. Deleting the bucket is the most reliable way to ensure that you do not miss any billable resources and incur unexpected fees. Note that data cannot be recovered after deletion. The bucket name also becomes available for other users to register. To completely stop using the OSS service, you must delete all buckets under your account.

Warning
  • After a bucket is deleted, its name is released and can be claimed by other users. If you want to retain the bucket name, empty the bucket instead of deleting it.

  • Data in a deleted bucket cannot be recovered. Before you delete a bucket, confirm that the data is no longer needed. If you want to continue using the data, create a backup in advance. For more information, see Back up a bucket.

Precautions

Before you delete a bucket, make sure that you have deleted the required resources.

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 shows how to delete a bucket named examplebucket:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # The China (Hangzhou) region is used as an example. Specify the actual Endpoint for your region.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)
# Specify the bucket name. For example, examplebucket.
client.delete_bucket('examplebucket')

References

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