How to fix 'Access Denied' while deleting empty S3 Elastic Beanstalk?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
If an S3 bucket used by Elastic Beanstalk looks empty but deletion still returns Access Denied, the problem is usually permissions or hidden bucket state rather than visible files. The usual causes are bucket-policy denies, versioned objects, shared Elastic Beanstalk usage, or an IAM principal that can view the bucket but cannot fully remove it.
Confirm the Bucket Is Safe to Delete
Elastic Beanstalk often stores application versions in S3, and in many accounts there is a shared regional bucket rather than a separate bucket per environment. Before deleting anything, verify that no existing application versions still reference that bucket.
If application versions still depend on the bucket, deleting it can break redeployments, rollbacks, or cleanup workflows. In many cases the right fix is to delete or migrate application versions first, not to remove the bucket itself.
Check IAM Permissions
The identity performing the delete needs enough S3 permissions to inspect and remove the bucket. Typical required permissions include:
- '
s3:ListBucket' - '
s3:DeleteBucket' - '
s3:DeleteObject' - '
s3:DeleteObjectVersion' - sometimes
s3:GetBucketPolicyands3:DeleteBucketPolicy
Example IAM policy fragment:
If any one of these permissions is missing, S3 can reject the delete even when the bucket appears empty in the console.
Check for an Explicit Bucket Policy Deny
Even broad IAM permissions do not override an explicit deny in the bucket policy. That is one of the most common reasons administrators see Access Denied despite having what looks like an admin role.
Inspect the bucket policy:
If the policy contains an explicit deny for delete operations, for your principal, or for your network path, that must be changed before deletion can succeed. If appropriate, remove the policy:
Only do that if you are sure the policy is no longer needed.
The Bucket May Not Be Truly Empty
An S3 bucket can look empty and still contain versions or delete markers. If versioning was enabled, those hidden entries must be removed before the bucket itself can be deleted.
Check versioning:
Then list versions and delete markers:
If that command returns entries, the bucket is not truly empty. You must delete the versions before deleting the bucket.
Ownership and Compliance Controls
In some environments, the bucket or its objects may be owned by a different AWS account, especially in cross-account CI or deployment setups. In that case, your principal may be able to inspect parts of the bucket but still lack permission to remove all object versions.
Also consider retention mechanisms such as Object Lock or organization-level controls. Those are less common in Elastic Beanstalk buckets, but they can still block deletion.
If a compliance rule is involved, repeated delete attempts will not help. You need to inspect the bucket's protective configuration first.
Practical Cleanup Sequence
A reliable manual flow is:
- confirm Elastic Beanstalk no longer needs the bucket
- verify IAM permissions for delete operations
- inspect the bucket policy for explicit denies
- inspect versioning and hidden object versions
- retry bucket deletion
Example CLI sequence:
If the bucket lives in a different region from your default CLI configuration, also verify that your CLI commands target the correct region.
Common Pitfalls
The biggest mistake is trusting the console's empty-bucket view too much. Versioned objects and delete markers can remain even when the file list looks empty.
Another common issue is trying to delete a shared Elastic Beanstalk bucket when the real goal is only to remove a specific application version. Those shared buckets often serve more than one deployment.
People also check IAM permissions but forget the bucket policy. In AWS, an explicit deny in the bucket policy wins.
Finally, do not forget object ownership. Cross-account uploads can leave behind versions that your current principal cannot remove.
Summary
- '
Access Deniedusually means a policy or hidden-bucket-state problem, not just visible files.' - Confirm Elastic Beanstalk no longer depends on the bucket before deleting it.
- Check IAM permissions and the bucket policy together.
- Inspect versioning and delete markers because an apparently empty bucket may still contain hidden objects.
- Delete the bucket only after permissions, policy, and retained object state are fully cleared.
Related reading
- How to fix apt-get command not found on AWS EC2?
- How to force https on elastic beanstalk?
- How to force SSL for Kubernetes Ingress on GKE
- How to format a URL to get a file from Amazon S3?
- How to fix App Store Connect Operation ERROR ITMS-90771
- How to fix Attempted relative import in non-package even with __init__.py
- How to forward port in AWS Application load balancer ALB port forwarding
- How to Generate a Presigned S3 URL via AWS CLI

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.