Skip to main content

Triage and Remediation

Remediation

Using Console

To reduce “too many versions” for an AWS Lambda function using the AWS Console, you essentially need to (1) decide which versions to keep, (2) update aliases, and (3) delete old versions.Below are the step‑by‑step instructions.

1. Identify which versions can be deleted

  1. Sign in to the AWS Management Console.
  2. Go to Lambda:
    Services → Lambda.
  3. In the left pane, click Functions, then select your Lambda function.
  4. In the function view, select the Versions tab.
    • You will see: $LATEST and numbered versions (e.g., 1, 2, 3…).
Decide which versions to keep:
  • Keep any versions currently used by:
    • Aliases (e.g., prod, staging, beta)
    • Event source mappings / triggers tied to a specific version
  • Keep a small number of recent versions for rollback (e.g., last 3–5).

2. Check and update aliases (so deletes are safe)

  1. In the same function, go to the Aliases tab.
  2. For each alias (e.g., prod, dev):
    • Confirm which version it is pointing to.
  3. If an alias points to a version you plan to delete:
    • Click the alias name.
    • Click Edit.
    • Change Version to a version you intend to keep (e.g., the latest stable).
    • Click Save.
Do not delete any version still in use by an alias or a direct trigger.

3. Delete old Lambda versions

  1. Back in the Versions tab:
  2. For each old version you want to delete:
    • Click the radio button for that version (you must first click into that version’s detail page if there is no direct delete button in the list).
    • In the top‑right, choose ActionsDelete (or Delete version from the version details page).
    • Confirm the deletion.
Repeat for all old, unused versions.
Note: $LATEST cannot be deleted.

4. (Optional) Set a version cleanup policy using automation

The console has no built‑in “auto‑prune” for versions. To avoid this problem returning:
  • Adopt a policy like “keep only last N versions” and:
    • Use a scheduled Lambda (invoked by EventBridge) that uses the AWS SDK to:
      • List versions of a function
      • Exclude those used by aliases
      • Delete older ones beyond N
  • Or enforce version limits via your CI/CD process (delete older versions after each deployment).

Summary

  • Use Versions tab to list and delete old, unused versions.
  • Update Aliases first so they don’t reference versions you’ll delete.
  • Keep only a small set of recent, active versions going forward and automate cleanup if possible.
For AWS Lambda, “Too many versions present” means you’re hitting/approaching the 75-version-per-function limit. You fix it by deleting old, unused versions.Below are step‑by‑step AWS CLI steps.

1. Identify functions with many versions

To see exactly how many versions a function has:

2. List all versions (to decide what to keep)

Decide:
  • KEEP: $LATEST
  • KEEP: versions used by aliases (e.g., prod, staging, etc.)
  • DELETE: old versions not used by aliases

3. Find which versions are in use by aliases

Make a note of all FunctionVersion values here; do not delete these.

4. Delete old versions (manually)

Delete a specific version (not $LATEST):
Repeat for each unneeded version.

5. Delete old versions (scripted, keeping latest N and alias‑targets)

Example: keep the 10 most recent versions + all versions used by aliases.

6. (Optional) Clean up across all functions

List all functions and loop:

After cleaning up, re-run:
to confirm the number of versions is reduced below your target (and below the limit).
In AWS Lambda, “too many versions present” means you’re hitting or approaching the 75 versions per function limit. The fix is to clean up old versions safely, keeping only the ones actively used (by aliases or other references).Below are step‑by‑step instructions plus a Python example you can run (locally or as its own Lambda) to delete old versions.

1. Decide Your Retention Policy

Before deleting anything, choose rules like:
  • Keep all versions referenced by aliases (e.g., prod, dev, staging).
  • Keep the N most recent versions (e.g., last 10).
  • Delete everything else.
Example policy we’ll implement:
  • Keep:
    • All aliased versions
    • Last 10 published versions
  • Delete:
    • All older, unaliased versions

2. IAM Permissions Needed

Ensure the identity running the script has these permissions on the function(s):
If targeting many functions, widen the Resource to match a pattern.

3. Python Script to Clean Up Old Versions

Install boto3 if running locally:
Python code (adjust config at the top):

4. Safe Execution Process

  1. Dry run first
    • Comment out the delete_version(...) call and just print which versions would be deleted.
    • Confirm:
      • No version used by prod, staging, etc. will be deleted.
      • You’re okay losing those historic versions.
  2. Backup / change control
    • (Optional but recommended) Export function configuration or code, or rely on your CI/CD source of truth.
  3. Run in non‑prod first
    • Test the script on a dev/staging Lambda.
  4. Run with deletes enabled
    • Uncomment delete_version call.
    • Execute for each target function.

5. Optional: Extend to Multiple Functions

You can list all functions and loop:

6. Prevent Recurrence

  • Integrate this script into:
    • A scheduled Lambda (CloudWatch Events / EventBridge rule, e.g., daily/weekly).
    • Your CI/CD pipeline after deployments.
  • Optionally, make your pipeline avoid publishing unnecessary versions unless needed.
This will keep Lambda from reaching the “too many versions” limit again.
Terraform does not expose any argument to limit or automatically delete old Lambda versions; to remediate “too many versions present” you must delete old versions via AWS Console or a script/CLI outside Terraform (e.g., aws lambda list-versions-by-function + delete-function --qualifier). After updating Terraform as above, terraform plan should show no further changes related to Lambda versions unless you modify the function itself.