Fixing the Bucket is not empty error when deleting a bucket
Issue description
You get the Bucket is not empty error when trying to delete a bucket.
Solution
To delete a folder or bucket, you need to first delete all objects from it. Here are the most common reasons why you cannot delete a bucket:
- Some multipart uploads are incomplete in the bucket.
- The bucket still contains uploaded objects.
- All objects have been deleted from the bucket but since versioning is enabled, the old versions of the deleted objects still exist.
You can delete all old versions of objects and incomplete uploads by setting up automatic deletion of all these entities in the bucket lifecycle rule.
Note
Lifecycle rules are processed at 00:00 UTC every day.
You can view and delete incomplete uploads using the management console
Learn how to delete all objects from a bucket using the management console in this article.
-
You can check for incomplete multipart uploads using this command:
aws --endpoint <https://storage.yandexcloud.net> s3api list-multipart-uploads \ --bucket \<bucket_name\> -
You can abort such uploads using the
abort-multipart-uploadcommand:aws --endpoint <https://storage.yandexcloud.net> s3api abort-multipart-upload \ --bucket \<bucket_name\> --key \<object_key\> --upload-id \<upload_id\> -
You can check for objects in the bucket using the
list-objectscommand:aws --endpoint <https://storage.yandexcloud.net> s3api list-objects \ --bucket \<bucket_name\> -
You can delete a single object using the
delete-objectcommand:aws --endpoint <https://storage.yandexcloud.net> s3api delete-object \ --bucket \<bucket_name\> --key -
You can delete multiple objects using the
delete-objectcommand:aws --endpoint <https://storage.yandexcloud.net> s3api delete-objects \ --bucket \<bucket_name\> --delete '\{ "Objects": \[ \{ "Key": \}, \{ "Key": \}, ...\] \}' -
If you have versioning enabled in your bucket, the old versions are still retained even after you delete all objects from your folder or bucket. You need to delete them as well. You can view the old versions by running this command:
aws --endpoint <https://storage.yandexcloud.net> s3api list-object-versions \ --bucket \<bucket_name\> -
You can delete a specific version of an object with this command:
aws --endpoint <https://storage.yandexcloud.net> s3api delete-object \ --bucket \<bucket_name\> --key \<key_name\> --version-id \<version_id\>