
Give Every AWS Sandbox a Return Date
A lease-based cleanup pattern for short-lived AWS environments, using explicit ownership, grace periods, and safe deletion gates instead of forgotten tags.
Give Every AWS Sandbox a Return Date
Cloud resources rarely become expensive because someone deliberately left them running. More often, a useful experiment ends, its owner moves on, and the environment quietly stays behind.
Tags such as
Environment=dev help identify resources, but they don’t answer the important question: When should this environment be reviewed or removed?Try treating a sandbox like a library book. Every environment gets an owner, a purpose, and a return date. When that date arrives, the system starts a predictable checkout process—not an instant, indiscriminate deletion.
The lease model
Keep the first version deliberately narrow: apply it to temporary environments deployed as CloudFormation stacks in a dedicated sandbox account.
At deployment, record a few pieces of metadata:
1
2
3
4
5
LeaseOwner: alex@example.com
LeasePurpose: test-new-search-index
LeaseExpiresAt: 2026-11-01
LeaseMode: notify-then-delete
LeaseHold: "false"The exact storage format can vary. Stack tags may be enough for a small proof of concept; a DynamoDB registry can make ownership, renewal history, and cleanup status easier to query as the system grows.
The key is that an expiry date is not just a tag nobody reads. It drives a process.
A cleanup flow that earns trust
A scheduled Lambda checks the lease records once a day and moves eligible stacks through these stages:
- Reminder: Notify the owner before the expiry date, with a link or clear instructions for requesting more time.
- Grace period: When the lease expires, mark the stack as pending cleanup and notify the owner again. Give teams a short, documented window to renew it.
- Safety check: Before any deletion, confirm that the stack is in the sandbox account, explicitly enrolled in the lease process, past its grace period, and not marked with
LeaseHold=true. - Cleanup: Delete only the eligible CloudFormation stack, then record the outcome and notify the owner.
A renewal should update the expiry date and leave an audit trail. A hold should pause deletion, but require an owner and a reason so “temporary” doesn’t quietly become “forever.”
Make the first version intentionally boring
Don’t begin by scanning every resource in every account and trying to infer what is safe to delete. Start with one stack boundary and one account designed for experiments.
That constraint makes the first version easier to review:
- Workloads must be deployed as CloudFormation stacks to participate.
- Production accounts and shared infrastructure are out of scope.
- Stacks that contain data needing preservation must use a separate retention process.
- The cleanup role should be limited to the intended sandbox workflow.
- Every attempted cleanup should be logged, including skipped stacks and the reason they were skipped.
The safest cleanup automation is not the one that can delete the most. It’s the one whose boundaries are easy to explain.
The human interface matters
A cleanup email that says “your stack will be deleted” creates anxiety. A useful notification says what the stack is, who owns it, when its lease expires, what will happen next, and how to renew or request a hold.
That turns cleanup from a surprise into a normal part of using the platform. Teams can experiment freely because the exit path is visible from the beginning.
Measure whether the pattern works
Track a few simple signals: how many stacks expire, how many are renewed, how many are deleted, and how many cleanup attempts are blocked by safety checks. Review skipped stacks regularly—those cases often reveal unclear ownership or a missing platform feature.
The goal isn’t to punish teams for keeping resources. It’s to make temporary infrastructure genuinely temporary, without relying on someone remembering to clean it up.
A sandbox should have a return date for the same reason a good experiment has an owner: when the work is done, everyone should know what happens next.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article