Delete a CloudBox bucket

更新时间:
复制 MD 格式

If you no longer need an OSS on CloudBox bucket, you can delete it to avoid unnecessary charges.

Prerequisites

  • All objects in the OSS on CloudBox bucket have been deleted.

    • To manually delete a small number of objects, see Delete objects.

    • If the bucket contains a large number of objects, use lifecycle rules to delete them in batches. For more information, see CloudBox lifecycle rules.

    Important

    If versioning is enabled for the bucket, you must delete all current and previous versions of all objects in the bucket.

  • All parts from multipart and resumable uploads have been deleted from the bucket.

Procedure

OSS console

  1. Log on to the OSS console.

  2. In the left-side navigation pane, choose Data Service > OSS on CloudBox Buckets. On the OSS on CloudBox Buckets page, click the name of the target bucket.

  3. In the left-side navigation pane, click Delete Bucket.

  4. Click Delete Bucket and follow the on-screen instructions.

Alibaba Cloud SDK

To delete an OSS on CloudBox bucket by using an SDK, you must use the OSS SDK for Java version 3.15.0 or later.

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;

public class Demo {

    public static void main(String[] args) throws Exception {
        // Specify the endpoint of the region where your CloudBox is located.
        String endpoint = "https://cb-f8z7yvzgwfkl9q0h****.cn-heyuan.oss-cloudbox.aliyuncs.com";
        // Obtain access credentials from environment variables. Before you run this code sample, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
        EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
        // Specify the name of your OSS on CloudBox bucket, for example, examplebucket.
        String bucketName = "examplebucket";
        // Specify the region where your OSS on CloudBox bucket is located.
        String region = "cn-hangzhou";
        // Specify the CloudBox ID.
        String cloudBoxId = "cn-hangzhou-test-1";

        // Create an OSSClient instance.
        // When you no longer need the OSSClient instance, call the shutdown method to release its resources.
        ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
        conf.setSignatureVersion(SignVersion.V4);
        OSS ossClient = OSSClientBuilder.create()
                .endpoint(endpoint)
                .credentialsProvider(new DefaultCredentialProvider(credentialsProvider.getCredentials()))
                .clientConfiguration(conf)
                .region(region)
                .cloudBoxId(cloudBoxId)
                .build();

        try {
            // Delete the OSS on CloudBox bucket.
            ossClient.deleteBucket(bucketName);
        } catch (OSSException oe) {
            System.out.println("Caught an OSSException, which means your request made it to OSS, "
                    + "but was rejected with an error response for some reason.");
            System.out.println("Error Message:" + oe.getErrorMessage());
            System.out.println("Error Code:" + oe.getErrorCode());
            System.out.println("Request ID:" + oe.getRequestId());
            System.out.println("Host ID:" + oe.getHostId());
        } catch (ClientException ce) {
            System.out.println("Caught an ClientException, which means the client encountered "
                    + "a serious internal problem while trying to communicate with OSS, "
                    + "such as not being able to access the network.");
            System.out.println("Error Message:" + ce.getMessage());
        } finally {
            if (ossClient != null) {
                ossClient.shutdown();
            }
        }
    }
}

Ossutil

For information about how to use ossutil to delete a bucket, see delete-bucket.

REST API

For highly customized applications, you can send REST API requests directly. To do this, you must manually write code to calculate the signature. For more information, see DeleteBucket.

FAQ

Cannot delete bucket

The deletion might fail if the OSS on CloudBox bucket is not empty or if you have insufficient permissions. Troubleshoot the issue based on the following causes:

  • The OSS on CloudBox bucket is not empty

    You cannot delete a non-empty bucket. Ensure that you have deleted all objects and parts from the OSS on CloudBox bucket.

  • Insufficient permissions

    The bucket is empty, but the RAM user does not have the required permissions. Add or modify permissions as described below:

    • Missing the oss-cloudbox:DeleteBucket permission: If you are a RAM user and cannot delete the OSS on CloudBox bucket, ask an administrator to add the oss-cloudbox:DeleteBucket permission to your RAM policy.

    • The effect for oss-cloudbox:DeleteBucket is Deny: If you have the oss-cloudbox:DeleteBucket permission in a RAM policy but still cannot delete an OSS on CloudBox bucket, the bucket policy may contain the oss-cloudbox:DeleteBucket permission with an effect of Deny. You must change the effect from Deny to Allow or delete this bucket policy before you can delete this bucket.

Cannot reuse bucket name

After you delete an OSS on CloudBox bucket, you must wait several hours (typically 4 to 8 hours) before you can create another bucket with the same name. Note that after a bucket is deleted, its globally unique name is released and can be claimed by any user.