If you no longer use an Object Storage Service (OSS) bucket, you can delete the bucket to prevent unnecessary charges.
A deleted bucket cannot be restored. Make sure that the data in the bucket is no longer needed before you delete the bucket. If you want to continue using the data in the bucket, back up the data in advance. For more information, see Back up buckets.
Prerequisites
The access points of the bucket are deleted. For more information, see Overview.
All objects in the bucket are deleted.
ImportantTo delete a versioned bucket, make sure that all current and previous versions of objects in the bucket are deleted. For more information, see Overview.
If the bucket contains a small number of objects, we recommend that you manually delete them. For more information, see Delete objects.
If the bucket contains a large number of objects, we recommend that you configure lifecycle rules to delete the objects. For more information, see Overview.
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.
Usage notes
Before you run the sample code in this topic, you must create an OSSClient instance by using methods such as using a custom domain name or Security Token Service (STS). For more information, see Initialization.
NoteWhen you initialize an OSSClient instance, specify an endpoint that maps to the region of the bucket that you want to delete.
The
oss:DeleteBucket
permission is granted to a RAM user if you want to use the RAM user to delete the bucket. For more information, see Attach a custom policy to a RAM user.NoteIf the RAM user has the
oss:DeleteBucket
permission in a RAM policy but cannot delete the bucket, another bucket policy that is attached to the RAM user may contain theoss:DeleteBucket
permission whose effect is Deny. In this case, you must change Deny to Allow or delete the bucket policy before you can delete the bucket.
Examples
The following sample 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;
}];
// Implement synchronous blocking to wait for the task to complete.
// [getdeleteTask waitUntilFinished];
References
For more information about the complete sample code that you can use to delete a bucket, visit GitHub.
For more information about the API operation that you can call to delete a bucket, see DeleteBucket.
For more information about how to initialize an OSSClient instance, see Initialization.