Catching Public S3 Buckets Before They Become a Headline
How I built a serverless, event-driven system on AWS Lambda, CloudTrail, and EventBridge that detects public S3 buckets within seconds and alerts security teams via Slack, with optional auto-remediation.
Public S3 buckets are one of the most common and most preventable causes of cloud data breaches. A single
PutBucketAcl or PutBucketPolicy call can turn a private bucket public in seconds, and in most organizations nobody notices until a scheduled scan runs hours later, or worse, until a researcher (or attacker) finds it first.I wanted to close that gap, so I built s3-bucket-detector : a serverless, event-driven system that detects public S3 buckets within seconds of the misconfiguration, alerts a Slack channel with actionable context, and can optionally auto-remediate.
The problem with scheduled scanning
Most bucket-auditing approaches run on a schedule hourly, daily, whatever the team can afford in compute and toil. That means the average public bucket sits exposed for however long is left on the clock before the next scan. For sensitive data, that window is the whole problem. An event-driven approach collapses it from hours to seconds by reacting to the change itself, not to a periodic sweep.
Architecture
The system is built entirely on managed, serverless AWS services:
- Cloud Trail captures every S3 API call that can affect public access ;
PutBucketAcl,PutBucketPolicy,PutPublicAccessBlock.
- EventBridge filters those Cloud Trail events down to the ones relevant to bucket exposure and routes them to a queue.
- SQS buffers events, smoothing out bursts and giving the pipeline built-in retries if Lambda throttles.
- Lambda does the actual work -it evaluates the bucket's resulting configuration, determines whether it's genuinely publicly exposed, optionally remediates it, and sends a Slack alert.
- Secrets Manager stores the Slack web hook URL, so no credentials live in code or environment variables.
- CloudWatch provides logs, custom metrics (
PublicBucketsDetected,DetectionLatency,RemediationsPerformed), and alarms for error rates and queue depth.
- An S3 reports bucket stores an audit trail of every detection and remediation — useful evidence for frameworks like SOC 2, HIPAA, or PCI-DSS.
Detection consistently lands under 5–10 seconds from the triggering API call.
Stack
- Python for detection, remediation, and Slack-notification logic
- Terraform, organized into reusable modules (
lambda,eventbridge,monitoring,s3) for repeatable infrastructure
- GitHub Actions for CI/CD
- SonarCloud integrated into the pipeline for code quality
- pytest, pytest-cov, and moto for unit tests, with a LocalStack path for integration testing
The repo includes a runbook, a Slack setup guide, and a multi-account deployment guide for teams running this across an AWS Organization.
Designing for safe automation
Auto-remediation is the most dangerous feature in a system like this if it's not designed carefully — a false positive that "fixes" the wrong resource is its own incident. So the system defaults to alert-only mode: it surfaces the exposure and lets a human decide. Remediation is an explicit opt-in via a Lambda environment variable, and the docs are explicit that it should be tested in a sandbox before enabling in production.
IAM roles are scoped to least privilege, secrets never touch environment variables, and encryption at rest is enabled for both S3 and CloudWatch Logs.
Cost
At roughly 1,000 S3 configuration-change events a day, the pipeline runs for a few dollars a month — Lambda, EventBridge, SQS, and CloudWatch Logs are all priced for exactly this kind of low-volume, event-driven workload. Scaled up to 10,000 events a day, it stays well under $20/month, a small cost against the impact of even a single bucket left open for hours.
What it demonstrates
Beyond wiring Lambda to EventBridge, this project is really about designing for production failure modes: buffering with SQS so bursts don't drop alerts, keeping secrets out of code, defaulting to "alert" rather than "act" until a human opts in, and building in the observability that makes an unattended system trustworthy.
The full implementation — Terraform modules, Lambda source, and setup docs — is on GitHub: github.com/Copubah/s3-bucket-detector . Feedback, issues, and PRs are welcome.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article