Delete bucket
Updated at:2025-11-03
Basic workflow
- Create an instance of the BOSClient class.
- Run the BosClient.deleteBucket method.
Example code
Plain Text
1try {
2 await bosClient.deleteBucket(bucketName);
3 logger.info(`delete ${bucketName} success`);
4} catch (bosResponse) {
5 logger.error(`errCode: ${bosResponse.error.code}`)
6 logger.error(`requestId: ${bosResponse.error.requestId}`)
7 logger.error(`errMessage: ${bosResponse.error.message}`)
8 logger.error(`statusCode: ${bosResponse.statusCode}`)
9}
Note
- If the bucket is not empty (i.e., it contains objects or unfinished three-step upload parts), it cannot be deleted. You must empty the bucket first to delete it successfully.
- Before deleting a bucket, verify that Cross-Region Replication (CRR) is not enabled for the bucket, and that it is neither the source nor target bucket in any CRR rules. Otherwise, the deletion will fail.
