2 Answers
- Newest
- Most votes
- Most comments
0
Short Answer
There’s no clean workaround here — keeping old versions is the correct and expected approach.
AWS will not delete a Lambda version while it’s still referenced by a running execution. With workflows that can run for months (or a year), deployment-time cleanup is fundamentally incompatible.
What You Should Do
- Set Lambda versions to
RemovalPolicy.RETAINin CDK - Treat versions as immutable artifacts
- Implement a separate cleanup process that deletes versions only when they’re no longer in use
Why This Is Actually Good Practice
- Old executions remain stable and reproducible
- New deployments don’t interfere with in-flight workflows
- You gain better auditability of historical behavior
Professional Growth Takeaway
You’re asking the right question — this is a classic distributed systems lifecycle issue.
The next step is to decouple deployment from execution lifecycle:
- Deploy freely
- Let long-running executions finish on pinned versions
- Clean up asynchronously and safely
For an extra step forward, consider adding version usage tracking (tags or external state) so cleanup becomes deterministic rather than guesswork.
answered 2 months ago
-1
May consider retaining legacy versions until those orchestrations are complete
Relevant content
- asked 4 months ago

Sure, but I consider this a workaround rather than the best solution. In a real world, professional environment I'm planning on potentially dozens of durable functions across several different CF stacks. Having to copy and paste cleanup script plumbing in each of these stacks feels like I'm just doing AWS's job for them.