Weekly AWS Lambda storage cleanup with a Slack summary

By General Input

Every Sunday night, clear out the old Lambda versions quietly filling your storage quota, log every deletion, and post the numbers to Slack.

Integrations

  • AWS Lambda
  • Google Sheets
  • Slack Bot

Type

Agentic Task

Categories

  • Engineering
  • Operations

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.

Related prompts

Explore more prompts
Call overdue Xero customers with an AI collections agentLocal listing health board for every location you manageLet support send one-off Loops emails without an engineerA brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensStop cold emails to anyone with a live deal in PipedriveLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasoniMessage campaign console with pre-flight checks and delivery board