DEV Community

Cover image for Your IR Runbook Is a PDF Nobody Reads at 3 AM. I Turned Mine Into a State Machine.

Your IR Runbook Is a PDF Nobody Reads at 3 AM. I Turned Mine Into a State Machine.

Le Beltagy on November 20, 2026

How I built an AWS forensic response pipeline with Step Functions, Python, Terraform, cross-account KMS and a human approval gate. Plus the Lambda ...
Collapse
 
dheerajramasahayam profile image
Dheeraj Ramasahayam •

This hit home from the data-center side — our 3 AM runbooks have the same problem, a step that says 'verify the link' with no record of what was actually checked. The line I keep coming back to is 'no response is not approval': on a night shift that is the difference between a clean handover and the next tech redoing your work blind. We learned the same lesson with ticket notes — if the evidence (DOM readings, what you swapped, what you ruled out) isn't in the ticket before the fix, the fix doesn't count as done.

Collapse
 
le_beltagy profile image
Le Beltagy •

Exactly, recording what was checked makes the next handover much easier.

Collapse
 
dheerajramasahayam profile image
Dheeraj Ramasahayam •

That's the part that saves the next shift — when the ticket already says what was checked and what came back clean, the person walking in at 3 AM doesn't re-run the same checks. On my floor the ticket line is the handover; if it isn't written down, it didn't happen.

Collapse
 
sudokat_ profile image
Gordon Chase •

Full copies on KMS re-encryption have a sneaky sidekick: EBS caps concurrent CopySnapshot jobs per region, so a multi-volume incident can throw ResourceLimitExceeded while big copies crawl. Right now raise_aws_error would file that as PermanentError and page straight out. Do you queue copies across an incident, or serialize them one volume at a time?

Collapse
 
le_beltagy profile image
Le Beltagy •

Good catch! I'd use a queue with bounded concurrency and treat that limit as retryable.

Collapse
 
kursatyz profile image
Kürşat Yılmaz •

Turning an IR runbook into Step Functions eliminates 3 AM decision fatigue, but it concentrates your failure surface into cross-account KMS key policies, Lambda cold-start timeouts, and the 256 KB state payload ceiling during forensic collection. Without strictly idempotent transitions and out-of-band break-glass permissions, a single revoked trust policy or SCP in the compromised account stalls containment mid-flight. Automation fails at the trust boundary.

Collapse
 
le_beltagy profile image
Le Beltagy •

Agreed, the trust boundary needs its own failure plan.

Collapse
 
ascendra_ventures_92c21f2 profile image
Ascendra Ventures •

"A runbook can tell people the correct order. It cannot stop an exhausted engineer from doing things in the wrong order." That sentence applies well beyond security.

We applied the same thinking to a much calmer problem at Ascendra Ventures: syncing Google Drive with a server you own. The dangerous step there is deletion, so the order is enforced by the tool rather than written down. Every sync is rehearsed as a dry run first. If a run would delete more files than your limit (ten by default), it stops and shows the list. Before the very first sync it shows what exists only locally, only on Drive, or differs on both, and waits for a typed confirmation. Anything replaced or deleted goes to a recovery folder before it is gone. None of that depends on someone remembering step four at 3 AM.

At your approval gate, does the approver see the evidence collected so far, such as snapshot IDs and the isolation result, or only the next action they are approving?

Collapse
 
le_beltagy profile image
Le Beltagy •

The approval view should include the snapshot IDs and isolation result so the decision has context.

Collapse
 
mariosfong profile image
Mario Fang •

I do not have Step Functions where I work — a few dozen servers, an ERP, an OA and one person who gets paged — so the closest thing I have to your state machine is a one-page decision tree with a named owner and a 15 minute timer written on it. Reading this, the parts that actually transferred were not the AWS ones.

Failure 3 is the one that made me put the phone down. We had our own version of a token in a URL: an isolation step was "approved" by replying in a chat channel, which means the approver was whoever the message happened to reach, and nothing ever expired. The result was a machine quarantined for nine days, because isolation worked perfectly and nothing owned the way out. Now the isolation ticket carries a name and a deadline and it escalates on its own, and no answer is never treated as approval — your first rule, and the only one I would call non-negotiable.

One addition to your measurement list, from the backup side of the same incident: a snapshot that exists is not evidence, and a restore that finishes is not evidence either. The ticket only closes when somebody has verified the restored data against something known — row count on a table that is actually used, a login that works, a report that runs. Otherwise you get a beautiful, auditable chain of custody for an artifact nobody has opened. The "a task token is a credential" line went straight into my notes.

Collapse
 
le_beltagy profile image
Le Beltagy •

Great point, verifying the recovered data belongs on that checklist too.

Collapse
 
gautamtalksdev profile image
Gautam K •

A human approval gate inside the state machine is the right call for forensics. Automate the snapshot and the isolation, keep the destructive steps behind a person. The snapshot copy timeout lesson is a good one to have written down.

Collapse
 
le_beltagy profile image
Le Beltagy •

Thanks! That snapshot timeout was a painful but useful lesson.

Collapse
 
upordownonline profile image
upordown.online •

The line that stuck with me is that a runbook can tell people the right order but can't stop them doing it in the wrong one. The risk I'd watch now is that the state machine only runs during real incidents, so it can drift the same way the PDF did: a KMS key policy changes, a role loses a permission, and nobody notices until 3 AM. A scheduled dry run against a throwaway tagged instance, say monthly, all the way to the approval gate and then rejected, would keep it honest.

Collapse
 
le_beltagy profile image
Le Beltagy •

Agreed, a monthly dry run through the rejection path would catch a lot of silent drift.

Collapse
 
kryeo profile image
Kryeo •

"It isn't a lock" is the line I wish more people learned before production. Tag-check-then-copy is the same check-then-write race that bites payment and order systems: two invocations both look, both see nothing, both act.

Really like that STARTING doesn't trigger a new copy but sends you to reconciliation instead. When the API gives you no idempotency token, "I don't know if it happened" has to be a real state you handle, not something a retry papers over.

Also "start in Lambda, wait in Step Functions" is a great one-liner for anyone who's watched a Lambda time out waiting on something slow. How often does the reconciliation path actually fire in practice, or has it mostly been theoretical so far?

Collapse
 
le_beltagy profile image
Le Beltagy •

I haven't shared production frequency data, but ambiguous results are exactly why that path matters.

Collapse
 
suquant profile image
George Kutsurua •

The approval gate uses waitForTaskToken, and investigations can last many days. What should happen if nobody approves it in that time?

Collapse
 
le_beltagy profile image
Le Beltagy •

It times out, keeps the instance isolated, and escalates to a human.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

two invocations can both see nothing and both copy. the conditional claim on the operation record is what stops the second copy.

Collapse
 
le_beltagy profile image
Le Beltagy •

Exactly, the conditional claim closes that race.

Collapse
 
robertpaschal profile image
Odinaka Robert Nnamani •

that closes it cleanly. one claim, no second copy to reconcile.

Collapse
 
wantsvibes_8504ec2bb0a7af profile image
wantsvibes •

Really interesting approach! We're also learning that having proper workflows and clear processes makes a huge difference when building and managing a platform. Turning documentation into something actionable rather than just keeping it as a reference is a great idea. Nice work!

Collapse
 
le_beltagy profile image
Le Beltagy •

Thanks! Making the process enforceable is where it starts paying off.

Collapse
 
raniaeltorgman profile image
Rania Torgman •

Such a great article 🚀 🚀🚀🚀

Collapse
 
le_beltagy profile image
Le Beltagy •

@raniaeltorgman thank you :)

Collapse
 
raniaeltorgman profile image
Rania Torgman •

😊

Collapse
 
parasraju profile image
Paras •

The task token as password point really landed.

Collapse
 
le_beltagy profile image
Le Beltagy •

Thanks! That token deserves the same care as any other credential.

Collapse
 
raniaeltorgman profile image
Rania Torgman •

Really helpful 👍

Collapse
 
le_beltagy profile image
Le Beltagy •

Glad you found it helpful 😊