`BucketNotEmpty: The bucket you tried to delete is not empty. You must delete all versions in the bucket.` even after `aws s3 rm --recursive`.
BeginnerTroubleshootingS3, EBS and EFS
Answer
Likely causes → Versioning is on. aws s3 rm only adds delete markers, and all older versions and delete markers remain.
Diagnose →
aws s3api get-bucket-versioning --bucket old-bucket
aws s3api list-object-versions --bucket old-bucket --max-items 5
Fix →
- For small buckets, delete versions in batches:
aws s3api list-object-versions --bucket old-bucket \
--query '{Objects: [Versions[].{Key:Key,VersionId:VersionId}, DeleteMarkers[].{Key:Key,VersionId:VersionId}][]}' \
--max-items 1000 --output json > del.json
aws s3api delete-objects --bucket old-bucket --delete file://del.json
- For big buckets, add a lifecycle rule that expires current and noncurrent versions and delete markers, wait a day, then delete the bucket
Prevent → In IaC, use force_destroy only for ephemeral buckets, and give every versioned bucket a noncurrent-version lifecycle rule.
More on S3, EBS and EFS
`BucketAlreadyExists: The requested bucket name is not available. The bucket namespace is shared by all users of the system.`Beginner`PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint.`BeginnerA partner account uploads objects into your bucket, but your own admins get `403 Forbidden` reading them.Intermediate`aws s3 cp` gets `An error occurred (AccessDenied) when calling the GetObject operation` but the IAM policy allows `s3:GetObject` and the bucket policy is fine.IntermediateAn S3 static website endpoint returns `403 Forbidden` with `Code: AccessDenied`.IntermediateHigh-throughput writes get `503 SlowDown: Please reduce your request rate.`Intermediate