AWS Builder Center

How to Lock Down an S3 Bucket From Scratch

The settings that actually prevent S3 data leaks — public access blocking, encryption, HTTPS enforcement, logging — set up right from the start.

Every few months there's a new headline about a company that leaked customer data because an S3 bucket was left wide open. It's almost never a sophisticated attack — it's usually a bucket that was public by accident, sitting there for anyone with the URL to browse. The frustrating part is that AWS actually makes this easy to prevent now. Most of it comes down to a handful of settings that take five minutes to configure.
Here's how to lock down an S3 bucket properly, from the moment you create it. You just need a free tier AWS account to follow along.

Why S3 buckets keep leaking

By default, S3 has gotten a lot safer over the years — new buckets block public access automatically now, which wasn't always the case. But people still turn that off without realizing what it does, usually while debugging a "why can't I access this file" problem and disabling the first setting that looks related. That single toggle is behind a huge share of the exposed-bucket stories you read about.
So the goal here isn't exotic security tooling. It's making sure the defaults stay on, plus a few extra layers that don't cost anything and take minutes to set up.

1. Block Public Access — leave it on

When you create a bucket today, AWS shows four checkboxes under "Block Public Access settings," and all four are checked by default:
  • Block public access via new ACLs
  • Block public access via any ACLs
  • Block public access via new bucket policies
  • Block public access via any bucket policies
Leave every single one checked unless you have a very specific, deliberate reason to host public content (like static website assets). If you do need public access for something specific, scope it down to that one prefix or object instead of turning off the account-wide protection.
If you're auditing existing buckets rather than creating new ones, this is the first thing to check. It's genuinely the single most important setting on this list.

2. Turn on default encryption

Data sitting in S3 should be encrypted at rest, and it's basically free to do:
  • SSE-S3 (Amazon S3 managed keys) — encryption is handled entirely by AWS, no extra setup, no cost. Good default for most use cases.
  • SSE-KMS (AWS Key Management Service) — gives you more control: you can set custom key policies, get audit logs of every time the key is used, and rotate keys on your own schedule. Worth it if you're storing anything sensitive or need to meet a specific compliance requirement.
New buckets have SSE-S3 on by default now, but it's still worth confirming — especially on older buckets created before this became the default.

3. Deny non-HTTPS requests explicitly

Block Public Access stops unauthorized public access, but it doesn't stop someone from connecting over plain HTTP instead of HTTPS if they do have valid credentials. A bucket policy can close that gap directly:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyInsecureTransport",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::your-bucket-name",
"arn:aws:s3:::your-bucket-name/*"
],
"Condition": {
"Bool": {
"aws:SecureTransport": "false"
}
}
}
]
}

This denies every S3 action on the bucket unless the connection is using HTTPS. It's a small addition, but it removes an entire category of downgrade attacks for basically zero effort.

4. Enable server access logging

Without logging, you have no way of knowing who accessed your bucket, when, or what they did — which becomes a real problem if something ever does go wrong and you need to investigate. Server access logging records every request made to the bucket (who, when, what action, from where) and writes those logs to a destination bucket you choose.
It's off by default, and it's one of those things nobody turns on until after an incident, when it's too late to have historical data. Turn it on when you create the bucket, not after.
A common setup is logging to a separate bucket (or a different prefix in the same bucket) dedicated to logs, so they don't mix with your actual data.

5. Use bucket policies over public ACLs, and keep them scoped

If you do need to grant access to specific people or services, prefer bucket policies (or IAM policies) over object-level ACLs. Bucket policies are centralized, easier to audit, and easier to reason about than a scattered mix of ACLs across individual objects.
And the same least-privilege logic from IAM applies here: grant  s3:GetObject  on a specific prefix instead of  s3:*  on the whole bucket if that's all a given role actually needs.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:role/read-only-app-role"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::your-bucket-name/reports/*"
}
]
}

This grants read access to one specific prefix ( reports/ ) for one specific role — not the entire bucket, not every principal.

The short version

Setting
Why it matters
Block Public Access
Prevents accidental public exposure — the #1 cause of S3 leaks
Default encryption
Protects data at rest, effectively free to enable
Deny non-HTTPS
Closes the downgrade-to-HTTP gap that public access blocking doesn't cover
Server access logging
Gives you visibility if something goes wrong later
Scoped bucket policies
Limits blast radius if a role or credential is compromised
None of this requires a security background — it's mostly flipping the right switches at bucket creation instead of after the fact. Every one of these takes a couple of minutes and either costs nothing or close to it, which makes skipping them hard to justify.
If you're setting up a bucket right now, walk through this list from the top before you upload anything to it. It's a lot easier than trying to clean up after a leak.
Got a specific scenario you're trying to lock down — static website hosting, cross-account access, replication? Drop a comment.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article