All Products
Search
Document Center

Object Storage Service:Delete a bucket

Last Updated:Dec 05, 2023

If you no longer use an Object Storage Service (OSS) bucket, you can delete the bucket to stop unnecessary charges.

Warning

Deleted buckets cannot be recovered. Make sure that the data in the buckets is no longer needed before you delete the buckets. If you want to continue using the data in the buckets, back up the data in advance. For more information, see Back up buckets.

Prerequisites

  • All objects in the bucket are deleted. You can manually delete objects from a bucket or have objects automatically deleted from a bucket based on a lifecycle rule.

    • If the bucket contains a small number of objects, we recommend that you manually delete them. For more information, see Delete objects.

    • To delete a large number of objects, we recommend that you configure lifecycle rules to delete the objects. For more information, see Configure lifecycle rules.

    Important

    To delete a versioning-enabled bucket, make sure that all current and previous versions of objects in the bucket are deleted. For more information, see Configure versioning.

  • Parts generated by multipart upload or resumable upload tasks in the bucket are deleted. For more information, see Delete parts.

  • All LiveChannels in the bucket are deleted. For more information, see DeleteLiveChannel.

Examples

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

OSSDeleteBucketRequest * delete = [OSSDeleteBucketRequest new];
// Specify the name of the bucket. Example: examplebucket. 
delete.bucketName = @"examplebucket";
OSSTask * deleteTask = [client deleteBucket:delete];
[deleteTask continueWithBlock:^id(OSSTask *task) {
    if (!task.error) {
        NSLog(@"delete bucket success!");
    } else {
        NSLog(@"delete bucket failed, error: %@", task.error);
    }
    return nil;
}];

References

  • For the complete sample code that is used to delete a bucket, visit GitHub.

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