Delete buckets
To delete an R2 bucket, you must first remove all objects from it. Once the bucket is empty, you can delete it.
Emptying a bucket deletes every object inside it. The bucket itself and its configuration (lifecycle rules, CORS, event notifications, custom domains) are preserved.
Objects removed during this process cannot be recovered. If your bucket has bucket lock rules, you must remove them before emptying the bucket.
You can empty a bucket in various ways.
The dashboard provides an Empty Bucket action that handles this for you, regardless of how many objects the bucket contains. For large buckets, the operation runs in the background and the dashboard displays progress until all objects have been removed.
-
In the Cloudflare dashboard, go to the R2 object storage page.
Go to Overview -
Select the bucket you want to empty.
-
Go to the Settings tab.
-
Scroll to the Empty Bucket section.
-
Select Empty.
-
Confirm the action in the dialog that appears.
You can configure an object lifecycle rule that expires all objects in the bucket.
- Add a lifecycle rule with no prefix filter and an expiration of 1 day.
- Wait for the rule to take effect. Objects are typically removed within 24 hours, but large buckets may take longer.
- After the bucket is empty, remove the lifecycle rule.
Add a lifecycle rule that expires all objects after 1 day:
npx wrangler r2 bucket lifecycle add <BUCKET_NAME> --expire-days 1After the bucket is empty, remove the rule:
npx wrangler r2 bucket lifecycle remove <BUCKET_NAME> --id <RULE_ID>For the full list of lifecycle commands, refer to Wrangler R2 commands.
You can also configure lifecycle rules using the S3 API or the dashboard. For more information, refer to Object lifecycles.
You can also write a script that lists and deletes objects in batches using the S3 API or Workers API, or use rclone to remove objects from the command line.
Once a bucket is empty, you can permanently delete it. Deleting a bucket removes the bucket and all of its configuration, including lifecycle rules, CORS settings, event notifications, and custom domains.
You can delete a bucket in various ways.
-
In the Cloudflare dashboard, go to the R2 object storage page.
Go to Overview -
Select the bucket you want to delete.
-
Go to the Settings tab.
-
Scroll to the Delete Bucket section. If the bucket is not empty, select Empty Bucket first to clear all objects.
-
Select Delete.
-
Confirm the action in the dialog that appears.
Use the r2 bucket delete command to delete an empty bucket:
npx wrangler r2 bucket delete <BUCKET_NAME>The command fails if the bucket still contains objects. Empty the bucket before running this command.
Use the delete bucket API endpoint to delete an empty bucket:
curl -X DELETE "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/r2/buckets/<BUCKET_NAME>" \ -H "Authorization: Bearer <API_TOKEN>"If the bucket is in a jurisdiction, include the cf-r2-jurisdiction header:
curl -X DELETE "https://api.cloudflare.com/client/v4/accounts/<ACCOUNT_ID>/r2/buckets/<BUCKET_NAME>" \ -H "Authorization: Bearer <API_TOKEN>" \ -H "cf-r2-jurisdiction: eu"- A bucket must be completely empty before it can be deleted. Attempting to delete a bucket that contains objects returns an error.
- You cannot empty a bucket that has bucket lock rules. Remove all lock rules before emptying the bucket.
- Event notifications configured on the bucket are removed when the bucket is deleted.
- If you use a custom domain with the bucket, remove the domain association before or after deletion to avoid dangling DNS records.