All Products
Search
Document Center

Object Storage Service:Delete a bucket (iOS 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 you delete a bucket, its name is released. Other users can then use the name. If you want to keep the bucket name, empty the bucket instead of deleting it.

  • Data in a deleted bucket cannot be recovered. Before you delete a bucket, make sure that you no longer need its data. To keep the data, back it up first. For more information, see Back up a bucket.

Prerequisites

  • All access points of the bucket are deleted. For more information, see Access points.

  • All objects in the bucket are deleted.

    Important

    If versioning is enabled for the bucket, make sure that all current and previous versions of objects in the bucket are deleted. For more information, see Versioning.

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

    • If the bucket contains many objects, you can configure lifecycle rules to delete them automatically. For more information, see Lifecycle.

  • All parts generated by multipart uploads or resumable uploads in the bucket are deleted. For more information, see Delete parts.

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

Usage notes

Before you run the sample code in this topic, you must create an OSSClient instance. You can create the instance using a custom domain name or Security Token Service (STS). For more information, see Initialization (iOS SDK).

Note

The region of the bucket that you want to delete is determined by the endpoint that you configure during initialization.

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.

Note

If you have the oss:DeleteBucket permission in a RAM policy but cannot delete the bucket, a bucket policy might contain an oss:DeleteBucket permission with its effect set to Deny. You must change the effect to Allow or delete the bucket policy before you can delete the bucket.

Sample code

The following code shows how to delete a bucket named examplebucket.

OSSDeleteBucketRequest * delete = [OSSDeleteBucketRequest new];
// Specify the bucket name. For 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;
}];
// Block the current thread until the task is complete.
// [getdeleteTask waitUntilFinished];

Related documents

  • For the complete sample code that shows how to delete a bucket, see the GitHub example.

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

  • For more information about how to initialize an OSSClient instance, see Initialization (iOS SDK).