All Products
Search
Document Center

Object Storage Service:Delete a bucket (Ruby SDK)

Last Updated:Mar 20, 2026

Delete a bucket when you no longer need it or want to stop being billed for it. OSS charges are mainly based on the resources inside a bucket, so deleting the bucket is the most reliable way to avoid unexpected fees. Deleted data cannot be recovered, and the bucket name becomes available for other users to register. To stop using OSS entirely, delete all buckets under your account.

Warning

Before you delete a bucket, be aware of the following:

  • The bucket name is released. After deletion, any user can register the same name. To keep the name, empty the bucket instead of deleting it.

  • Data cannot be recovered. Confirm that the data is no longer needed, or create a backup first. For details, see Back up a bucket.

Prerequisites

Before you begin, make sure that:

  • All resources in the bucket are deleted. For the required steps, see Delete the required resources.

  • Your account has the oss:DeleteBucket permission. By default, an Alibaba Cloud account has full permissions. RAM users and RAM roles have no permissions by default — grant access via RAM Policy or bucket policies.

APIActionDefinition
DeleteBucketoss:DeleteBucketDeletes a bucket.

Delete a bucket

The following example deletes a bucket named examplebucket:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # Replace with the endpoint for your region.
  # This example uses the China (Hangzhou) endpoint.
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # Load credentials from environment variables.
  # Set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET before running this code.
  access_key_id: ENV['OSS_ACCESS_KEY_ID'],
  access_key_secret: ENV['OSS_ACCESS_KEY_SECRET']
)

# Replace examplebucket with your bucket name.
client.delete_bucket('examplebucket')

API reference

For the underlying API operation, see DeleteBucket.