A build that used to take days of console work now takes one Terraform apply, in under an hour. And when the policy changes, it no longer means a rebuild. Here's how I got there, and what real environments taught me along the way.
The problem: the requirements kept moving
Every file that enters a secure network has to be scanned before anyone uses it. My team calls the system that does this the washing machine. Dirty data goes in, clean data comes out.
Building one washing machine is not hard. What makes it hard is that every new enclave answers the same questions differently:
- One or many? Some quarters the guidance was one shared washing machine at the front door. Other quarters, each enclave needed its own.
- Budget shaped the design. How a project was funded often decided whether it got a shared service or a custom build.
- Nobody owned the data. No one could say for sure who was allowed to put data where.
- No sizing inputs. How much data? How often? Nobody had written it down.
Each change meant another manual build. Each one came out a little different, and every difference cost trust. I couldn't fix the policy, but I could make it cheap to follow.
Solution overview
The pipeline uses only managed AWS services, so there is no scanning engine to patch or scale.
Click the diagram to see it full size.
- A data provider writes files to a landing bucket.
- Amazon GuardDuty Malware Protection for S3 scans each new object and tags the result.
- An Amazon EventBridge rule sends the result to two AWS Lambda functions in private subnets.
- The transfer function copies clean files to the clean bucket, sends files it can't scan to quarantine, and deletes malware.
- The alert function notifies the mission team through Amazon SNS.
- Amazon CloudWatch alarms on Lambda errors publish to the same topic, so a broken pipeline is never silent.
- Workloads read only from the clean bucket.
The most important rule is to fail closed. If there's no scan result, the file goes to quarantine, never to the clean bucket.
The key idea: make topology a variable
The question I couldn't answer was "one washing machine or ten?" So I stopped trying to answer it in the design.
The whole pipeline is one Terraform module. Where it runs, in a shared hub account or inside an enclave's own account, depends only on where you apply it and which network values you pass in. A few switches decide what is shared and what belongs to one mission, such as the quarantine bucket, the alert topic, and the scanner's IAM role.
By default, quarantine and alerts belong to each mission. A shared alert topic would send one team's malware alerts to another team's inbox, and that is a data governance problem of its own.
Now, when the guidance flips from central to per enclave, the work is a new configuration and one apply. It is not a rebuild.
The lockdown trap
Locking down your buckets so only trusted networks can reach them is good practice. But GuardDuty reaches S3 as a service, not from inside your network. If your deny policy doesn't exempt the GuardDuty scan role, every scan fails with ACCESS_DENIED, and every file ends up in quarantine.
The module adds that exemption automatically, so nobody has to remember it.
What real environments taught me
Guardrails can remove a service you planned around. My first design relied on a service that an organization policy turned out to block completely. No IAM change gets around that. I made that piece optional and moved the failure signal to CloudWatch alarms, which work everywhere. Check your organization's guardrails before you design, not after.
Private subnets need VPC endpoints. The Lambda functions run in subnets with no internet route. Without the right VPC endpoint, the alert function hung until it hit its timeout. If a Lambda function in a private subnet times out, check its endpoints first.
Prove it with a test virus. After every deploy, I upload the harmless EICAR test file. I confirm it's caught, that it never reaches the clean bucket, and that the alert arrives. A pipeline that has never caught anything has not been tested.
Read the whole plan. Once, an out-of-date variables file nearly undid a security change I had applied an hour earlier. The plan was meant to make one small change but also carried a silent reversal. I caught it only because I read every line.
Results
- Days to under an hour for a new deployment.
- Running in production in more than one environment. The smoke test passes and the alarms are live.
- The default template for every new enclave.
- Faster reviews, because change reviewers read code and a plan instead of screenshots.
Retrospective
Make the decision you can't make yet a variable. "One or ten?" was a policy question, not a technical one. I couldn't settle it, but I could make the answer cheap to change.
Missing requirements are a design input. Unclear ownership and unknown volume didn't stop the build. They shaped it. Separate quarantine and alerts for each mission exist because nobody had yet decided who may see whose data.
Consistency builds trust. Code that gives the same result every time, plus a test anyone can watch, earned more trust with customers and reviewers than any slide.
What I'd do differently: set up remote state on day one, and treat every variables file as production data from the first apply.
How do you handle shared versus per-tenant scanning in regulated environments? I'd like to hear about it in the comments.
Next in the series: one front door, and how a landing page fixed tool sprawl across communities.

