More Info:
Are there too many versions for any Lambda function?Risk Level
LowAddress
Compliance Standards
Triage and Remediation
- Remediation
Remediation
Using Console
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.
Note:
1. Identify which versions can be deleted
- Sign in to the AWS Management Console.
- Go to Lambda:
Services → Lambda. - In the left pane, click Functions, then select your Lambda function.
- In the function view, select the Versions tab.
- You will see:
$LATESTand numbered versions (e.g., 1, 2, 3…).
- You will see:
- Keep any versions currently used by:
- Aliases (e.g.,
prod,staging,beta) - Event source mappings / triggers tied to a specific version
- Aliases (e.g.,
- Keep a small number of recent versions for rollback (e.g., last 3–5).
2. Check and update aliases (so deletes are safe)
- In the same function, go to the Aliases tab.
- For each alias (e.g.,
prod,dev):- Confirm which version it is pointing to.
- 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.
3. Delete old Lambda versions
- Back in the Versions tab:
- 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 Actions → Delete (or Delete version from the version details page).
- Confirm the deletion.
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
- Use a scheduled Lambda (invoked by EventBridge) that uses the AWS SDK to:
- 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.
Using CLI
Using CLI
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.
To see exactly how many versions a function has:
Decide:
Make a note of all
Repeat for each unneeded version.
After cleaning up, re-run:to confirm the number of versions is reduced below your target (and below the limit).
1. Identify functions with many versions
2. List all versions (to decide what to keep)
- 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
FunctionVersion values here; do not delete these.4. Delete old versions (manually)
Delete a specific version (not$LATEST):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:
Using Python
Using Python
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.
If targeting many functions, widen the
Python code (adjust config at the top):
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.
- 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):Resource to match a pattern.3. Python Script to Clean Up Old Versions
Install boto3 if running locally:4. Safe Execution Process
-
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.
- No version used by
- Comment out the
-
Backup / change control
- (Optional but recommended) Export function configuration or code, or rely on your CI/CD source of truth.
-
Run in non‑prod first
- Test the script on a dev/staging Lambda.
-
Run with deletes enabled
- Uncomment
delete_versioncall. - Execute for each target function.
- Uncomment
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.
Using Terraform
Using Terraform
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.
