If you no longer need a bucket, you can delete it to stop all billing. Because Object Storage Service (OSS) fees are charged for the resources inside a bucket, you must clear all resources before deleting it. Deleting a bucket is the most reliable way to prevent unexpected fees from overlooked billable resources. Note that data cannot be recovered after a bucket is deleted, and another user can claim its name after it is released. To completely stop using OSS, you must delete all buckets in your account.
-
After a bucket is deleted, its name is released and can be claimed by another user. If you want to keep the bucket name, empty the bucket instead of deleting it.
-
Data in a bucket cannot be recovered after the bucket is deleted. Before you delete a bucket, confirm that the data is no longer needed. If you want to continue using the data in the bucket, back it up in advance. For more information, see Back up a bucket.
Precautions
-
Before you use the sample code in this topic, you must create an OSSClient instance using a custom domain name or Security Token Service (STS). For more information, see Initialize an OSSClient instance for Android.
-
Before you delete a bucket, make sure that you have deleted the required resources.
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 policies or Bucket Policy.
|
API |
Action |
Description |
|
DeleteBucket |
|
Deletes a bucket. |
If you have the oss:DeleteBucket permission in a RAM policy but cannot delete the bucket, it may be because a bucket policy contains the oss:DeleteBucket permission with the effect set to Deny. In this case, you must change the effect to Allow or delete the bucket policy before you can delete the bucket.
Sample code
The following code provides an example of how to delete a bucket:
DeleteBucketRequest deleteBucketRequest = new DeleteBucketRequest("bucketName");
// Asynchronously delete the bucket.
OSSAsyncTask deleteBucketTask = oss.asyncDeleteBucket(deleteBucketRequest, new OSSCompletedCallback<DeleteBucketRequest, DeleteBucketResult>() {
@Override
public void onSuccess(DeleteBucketRequest request, DeleteBucketResult result) {
Log.d("asyncDeleteBucket", "Success!");
}
@Override
public void onFailure(DeleteBucketRequest request, ClientException clientException, ServiceException serviceException) {
// The request failed.
if (clientException != null) {
// Client exceptions, such as network exceptions.
clientException.printStackTrace();
}
if (serviceException != null) {
// Service exceptions.
Log.e("ErrorCode", serviceException.getErrorCode());
Log.e("RequestId", serviceException.getRequestId());
Log.e("HostId", serviceException.getHostId());
Log.e("RawMessage", serviceException.getRawMessage());
}
}
});
Related documents
-
For the complete sample code for deleting a bucket, see the GitHub example.
-
For more information about the API operation for deleting a bucket, see DeleteBucket.
-
For more information about how to initialize an OSSClient instance, see Initialize an OSSClient instance for Android.