Weekly AWS Lambda storage cleanup with a Slack summary
Every Sunday night, clear out the old Lambda versions quietly filling your storage quota, log every deletion, and post the numbers to Slack.
Every Sunday at 10pm, audit my AWS Lambda code storage and prune the old published function versions that are quietly eating my 75GB per-region account quota.
Start with the AWS Lambda Get Account Settings operation to read my current code storage usage against the account code size limit for the region. Work out what percentage of the limit is in use, and hold on to that starting number for the summary at the end.
If usage sits below 60 percent of the limit, skip the deletions entirely. Post a single status line to Slack with the current usage and remaining headroom, then finish. This workflow should stay quiet until storage actually matters. Treat the 60 percent threshold as a setting I can change.
When usage is at or above that threshold, use List Functions to enumerate every function in the region. These list endpoints paginate with Marker and NextMarker, so page all the way through rather than reading only the first page. For each function, call List Versions By Function to get its published versions and List Aliases to see which versions are currently referenced.
Decide what is safe to delete using three hard rules that must never be broken: never touch $LATEST, never delete a version that any alias points to (including both the alias target and any versions named in an alias routing configuration), and always keep the three most recent published versions of every function. Treat the keep count of three as a setting I can change. Anything that fails any of these checks stays.
Delete what remains with Delete Function, passing the version as the qualifier so only that single version is removed and never the whole function. When a function name or ARN contains a colon, URL-encode it as %3A in the path. Record the code size of each version before deleting it so I know exactly how much was reclaimed.
Log every single deletion as a row in Google Sheets using Append Values, with the date, the function name, the version number, and the size reclaimed. These deletions are irreversible, so this log is my permanent audit trail. Write the rows as you go rather than batching them at the very end.
Once the pass is complete, call Get Account Settings again to read the storage figure after cleanup, then post a summary to Slack with Send a Message. Include storage used before and after, total GB reclaimed, the number of versions removed per function, and how much quota headroom is left. If nothing qualified for deletion, say so plainly instead of sending an empty report.
What does this prompt do?
- Checks how much of your AWS Lambda storage allowance is already used, and stays quiet when there is plenty of room left
- Finds old function versions that are safe to retire, always keeping the three newest and anything a live alias like prod or staging points at
- Records every removal in a Google Sheet with the date, function, version and space recovered, so you have a permanent trail
- Posts a Slack summary showing storage before and after, total space recovered, and how much headroom you have left
What do I need to use this?
- An AWS account with Lambda functions, plus access keys for the region you want cleaned up
- A Google account and a spreadsheet to hold the cleanup log
- A Slack workspace and a channel for the weekly summary
How can I customize it?
- Change how many recent versions to keep for each function (three by default)
- Move the quiet threshold up or down, so nothing is deleted until usage passes the level you set
- Pick a different day and time, a different Slack channel, or a different logging spreadsheet
FAQs
Can this delete something my production traffic depends on?
What happens if my storage is nowhere near full?
Why does Lambda storage fill up in the first place?
Can I undo a deletion?
Does it cover all of my functions at once?
Related templates
Stop buying stale lists. Reps run a saved search, work the results like an inbox, and only the accounts they approve ever reach your CRM.
See how your brand's news coverage and sentiment stack up against four competitors, then let an assistant write the weekly report for you.
One screen showing every social post waiting on approval, sorted by deadline, so reviewers can approve or reject without leaving the page.
Every Monday, find the past champions and closed-won contacts who changed jobs, update Attio, and get the moves worth chasing in Slack.
Staff submit what happened, your social manager edits the copy, picks the accounts and puts it on the calendar without a single spreadsheet.
Drag creators through Sourced to Wrapped on a board grouped by campaign, with audience stats on every card and a one-click brief for each creator.
Stop letting old Lambda versions break your deploys.
Set this up once and your storage quota looks after itself every Sunday night, with a full record of everything that was removed.