Delete a bucket when you no longer need it or want to stop incurring storage charges. Because OSS charges are based on resources inside the bucket, deleting the bucket is the most reliable way to avoid unexpected fees. Deletion is permanent — data cannot be recovered, and the bucket name becomes available for other users to register.
Bucket names are released immediately. After deletion, any user can register the same name. To keep the name, empty the bucket instead of deleting it.
Data cannot be recovered. Back up any data you need before deleting the bucket. For more information, see Back up a bucket.
Prerequisites
Before you begin, ensure that you have completed all of the following:
Deleted all access points attached to the bucket. For more information, see Access points.
Deleted all objects in the bucket.
ImportantIf versioning is enabled, delete all current and previous versions of every object. For more information, see Versioning.
For a small number of objects, delete them manually. See Delete objects.
For a large number of objects, use lifecycle rules to automate deletion. See Lifecycle.
Deleted all parts generated by multipart uploads or resumable uploads. For more information, see Delete parts.
Deleted all LiveChannels in the bucket. For more information, see DeleteLiveChannel.
Usage notes
Before running the sample code, create an OSSClient instance using a custom domain name or Security Token Service (STS). For more information, see Initialization (iOS SDK).
The region of the bucket is determined by the endpoint you configure during initialization.
Permissions
By default, an Alibaba Cloud account has full permissions. RAM users and RAM roles have no permissions by default and must be granted access through a RAM policy or bucket policy.
| API | Action | Description |
|---|---|---|
| DeleteBucket | oss:DeleteBucket | Deletes a bucket |
If you have the oss:DeleteBucket permission in a RAM policy but cannot delete the bucket, a bucket policy may contain an oss:DeleteBucket permission with its effect set to Deny. Change the effect to Allow or delete the bucket policy, then try again.
Sample code
Ensure the bucket is empty and all prerequisites above are met before calling this API.
The following code deletes a bucket named examplebucket.
Objective-C
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.
// [deleteTask waitUntilFinished];For the complete sample, see the GitHub example.
Troubleshooting
If the deletion fails, check the following:
The bucket is not empty. The bucket must have no objects, parts, LiveChannels, or access points. See Prerequisites.
You lack the `oss:DeleteBucket` permission. Contact your Alibaba Cloud account administrator to grant you the permission via a RAM policy or bucket policy.
A bucket policy is blocking the deletion. If you have
oss:DeleteBucketin your RAM policy but still cannot delete the bucket, a bucket policy may have anoss:DeleteBucketDeny statement. Change the effect to Allow or delete the bucket policy, then try again.
Related topics
For API details, see DeleteBucket.
To initialize an
OSSClientinstance, see Initialization (iOS SDK).