If you no longer use a bucket, delete the bucket to stop unnecessary charges.

Warning Deleted buckets cannot be recovered. Exercise caution when you perform this operation.

Prerequisites

  • All objects in the bucket are deleted.
    • For more information about how to manually delete a small number of objects, see Delete objects.
    • If you want to delete a large number of objects, we recommend that you configure lifecycle rules to delete the objects in batches. For more information about how to delete a large number of objects, see Configure lifecycle rules.
    Notice

    If versioning is enabled for the bucket that you want to delete, make sure that all versions of objects in the bucket are deleted. For more information about how to delete all versions of objects in a bucket, see Configure versioning.

  • Parts generated by multipart upload or resumable upload tasks in the bucket are deleted. For more information about how to delete parts in a bucket, see Manage parts.
  • All LiveChannels in the bucket are deleted. For more information about how to delete LiveChannels, see DeleteLiveChannel.

Sample code

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

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. 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. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')
# Specify the name of the bucket. Example: examplebucket. 
client.delete_bucket('examplebucket')

References

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