
From a Leaked Key to a $48,000 Bill: Anatomy of an AWS Breach (and How to Stop It)
A fictional but realistic story of how one committed access key turns into a full AWS compromise, told step by step from the attacker's point of view. At every stage you'll see the control that would have stopped it: secret scanning, least privilege, SCPs, GuardDuty, and budgets.
Note: The company, people, and numbers in this story are fictional, but every step reflects a pattern that is widely documented in real AWS incidents.
It's 9:12 AM on a Monday. Priya, a developer at a small startup, opens her email and sees a billing alert she never configured, because she never set one up. It arrives from her finance lead instead:
"Why is our AWS bill $48,000 this month? It's normally $300."
Nothing was hacked in a Hollywood sense. Nobody exploited a zero-day. A single file, pushed on a Friday evening, started everything. Let's replay the weekend from the attacker's side, and at each step see what would have changed the ending.
The Timeline at a Glance
Time | What happened | Control that would have stopped it |
|---|---|---|
Fri 6:40 PM | Priya pushes code with an .env file containing an access key | Pre-commit secret scanning, .gitignore |
Fri 6:46 PM | Automated scanners find the key in the public repo | Push protection, no long-lived keys |
Fri 6:50 PM | The key is tested and its permissions are explored | Least-privilege IAM |
Fri 7:30 PM | Compute is launched in many regions | SCP region restrictions, GuardDuty |
Sat 2:00 AM | Data is read, and a backdoor user is created | CloudTrail alerts, IAM monitoring |
Mon 9:12 AM | Finance notices the bill | AWS Budgets, billing alarms |

Act 1: The Mistake (Friday, 6:40 PM)
Priya was rushing to share a demo with a client. Her project read configuration from a local
.env file, which contained an AWS access key she'd created months ago for "quick testing." She ran git add . and pushed to a public repository.She noticed within the hour and deleted the file. But Git remembers everything. The key was still sitting in the commit history.
What would have stopped it:
- A
.gitignoreentry for.envfiles, set up on day one.
- Pre-commit secret scanning (tools like gitleaks or git-secrets) that blocks the commit on her laptop.
- GitHub secret scanning with push protection, which can reject the push itself.
- Most importantly: no long-lived access key at all. Local development can use IAM Identity Center (SSO) with temporary credentials that expire in hours.
Act 2: The Race (6:46 PM)
Six minutes later, the key was already found. This is the part that surprises people. Attackers don't browse repositories by hand. Automated bots watch public commit streams around the clock, searching for patterns that look like cloud credentials. Finding a key is a matter of minutes, not days.
AWS also watches for this. When a key appears in a public repository, AWS may notify the account owner and can attach a restrictive quarantine policy to the exposed user. That helps, but it is a safety net, not a plan. The email went to an inbox nobody was watching, and the quarantine policy limits only some actions.
Rule of thumb: if a secret has been public for even one minute, treat it as stolen. Deleting the file is not enough. Rotate or deactivate the key immediately, then investigate.
Act 3: Looking Around (6:50 PM)
The first thing an attacker does with a stolen key is ask: who am I, and what can I do? Harmless-looking API calls reveal the identity behind the key and which services respond. This phase is quiet and cheap, and it looks like normal API traffic.
Here is where Priya's old shortcut hurt her. Months earlier, tired of "Access Denied" errors, she had attached
AdministratorAccess to the testing user. The key could do everything.What would have stopped it:
- Least privilege. A key that can only read one S3 prefix limits the blast radius to that prefix.
- IAM Access Analyzer to spot unused permissions and tighten them.
- Permission boundaries so even a mistakenly broad policy can't exceed a ceiling.
- Conditions on policies, such as restricting use to specific source IP ranges or requiring MFA for sensitive actions.
Act 4: Making Money (7:30 PM)
With admin rights, the attacker's goal was simple and boring: turn your account into free computing power. Large GPU and compute-optimized instances were launched across many regions, including regions the startup had never used, to mine cryptocurrency. Spreading across regions makes the activity harder to spot in the console, since most people only look at the region they work in.
What would have stopped it:
- Service Control Policies (SCPs) that deny all actions outside the regions you actually use:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "DenyUnapprovedRegions", "Effect": "Deny", "NotAction": ["iam:*", "organizations:*", "sts:*", "support:*"], "Resource": "*", "Condition": { "StringNotEquals": { "aws:RequestedRegion": ["us-east-1", "eu-west-1"] } } } ]}- Service quotas kept low, so an account can't suddenly launch hundreds of large instances.
- Amazon GuardDuty, which has findings for cryptocurrency-related activity and for credentials being used from unusual locations. Enabling it in all regions would have raised alerts within hours.
Act 5: Staying Power (Saturday, 2:00 AM)
A careful attacker knows the original key might be discovered and revoked. So they create persistence: a new IAM user, a new access key, or a role that trusts an outside account. If Priya rotates the first key, the attacker still has a way in.
They may also read data they can reach, such as S3 buckets and database snapshots.
What would have stopped it:
- CloudTrail records every one of these actions. With alerts on events like
CreateUser,CreateAccessKey, andAttachUserPolicy, someone would have been paged at 2 AM instead of finding out on Monday.
- EventBridge rules that notify a team channel when IAM changes occur outside a pipeline.
- An SCP or permission boundary that blocks creating new IAM users from ordinary roles.
- S3 data protection: encryption with KMS keys, least-privilege bucket policies, and access logging.
Remember: the evidence only helps if logging is turned on and sent somewhere an attacker can't erase it. Send CloudTrail logs to a separate, locked-down logging account.
Act 6: The Bill (Monday, 9:12 AM)
Nobody noticed for three days, because nothing was watching the one metric that never lies: money.
What would have stopped it:
- AWS Budgets with alerts at 50%, 80%, and 100% of the expected monthly cost, plus a forecast alert.
- AWS Cost Anomaly Detection, which flags sudden spending spikes by service.
- A billing contact that goes to a monitored team mailbox, not one person's inbox.
AWS may sometimes help with charges that result from compromised credentials, but it is not guaranteed, and the cleanup is still painful. Prevention is far cheaper than hoping for a refund.
The Cleanup: What Priya Did Next
Once she realized what had happened, the response followed a standard order:
- Disable the exposed key immediately, then delete it after investigation.
- Review CloudTrail to find everything the key did, including new users, roles, keys, and resources.
- Remove attacker persistence: unknown IAM users, access keys, roles, and unexpected trust relationships.
- Terminate unauthorized resources in every region, not just the default one.
- Check data exposure: which buckets, snapshots, and secrets could the key reach? Rotate anything that might have been read.
- Contact AWS Support about the incident and the charges.
- Write a short post-incident review. The goal is learning, not blame.
The Five-Minute Prevention Plan
If you do only five things after reading this, make them these:
- [ ] Enable MFA on the root user and every human user.
- [ ] Replace long-lived access keys with SSO or IAM roles.
- [ ] Turn on secret scanning in your repositories, with push protection.
- [ ] Create an AWS Budget and billing alerts today.
- [ ] Enable GuardDuty and CloudTrail in all regions.
Conclusion
The scariest part of this story isn't the bill. It's how ordinary every step was. There was no genius attacker, only a rushed Friday, a convenient shortcut, and no alarms. Real-world cloud breaches usually look like this: small mistakes that line up.
The good news is that the same pattern works in reverse. Each act in this story had a simple, inexpensive control waiting to break the chain, and you only need one of them to work.
Have you ever found a secret in a repo, or caught a surprise on your AWS bill? Share what you learned in the comments (without the secret, please!).
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article