A bucket is a container for objects stored in OSS. Every object is contained in a bucket. This topic describes how to delete a bucket.

  • Before you delete a bucket, you must delete all objects in the bucket, LiveChannel objects, and fragments generated by multipart uploads. For more information about deleting a LiveChannel object, see LiveChannel.
  • To delete the parts generated by multipart upload, use ListMultipartUploads to list all the parts, and then use AbortMultipartUpload to delete these parts.

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

#include <alibabacloud/oss/OssClient.h>
using namespace AlibabaCloud::OSS;

int main(void)
    /*Initialize the OSS account information.*/
    std::string AccessKeyId = "yourAccessKeyId";
    std::string AccessKeySecret = "yourAccessKeySecret";
    std::string Endpoint = "yourEndpoint";
    std::string BucketName = "yourBucketName";

    /*Initialize network resources.*/

    ClientConfiguration conf;
    OssClient client(Endpoint, AccessKeyId, AccessKeySecret, conf);

    /*Specify the name of the bucket to delete.*/
    DeleteBucketRequest request(BucketName);

    /*Delete the bucket.*/
    auto outcome = client.DeleteBucket(request);

    if (! outcome.isSuccess()) {
        /*Handle exceptions.*/
        std::cout << "DeleteBucket fail" <<
        ",code:" << outcome.error().Code() <<
        ",message:" << outcome.error().Message() <<
        ",requestId:" << outcome.error().RequestId() << std::endl;
        return -1;

    /*Release network resources.*/
    return 0;

For more information about how to delete a bucket, see DeleteBucket.