This GitHub Action prunes published AWS Lambda versions using count-based (keep-latest) and age-based (older-than-days) rules.
The action runs as a JavaScript action on node24.
- Operates on one or multiple Lambda functions per run
- Supports using
keep-latestandolder-than-daystogether (OR condition) - Supports
dry-runmode to preview deletion candidates (default:false) - Excludes alias-referenced versions by default
This action assumes AWS credentials are configured by the caller workflow via OIDC.
Required IAM permissions:
lambda:ListVersionsByFunctionlambda:ListAliaseslambda:DeleteFunction
Minimum GitHub Actions permissions:
id-token: writecontents: read
| Name | Required | Type | Default | Description |
|---|---|---|---|---|
function-name |
Yes | string | - | Target Lambda function name(s), single or newline-separated |
aws-region |
Yes | string | - | Target AWS region |
keep-latest |
No | integer (>= 0) |
- | Keep the latest N versions |
older-than-days |
No | integer (>= 1) |
- | Select versions older than N days |
dry-run |
No | boolean (true/false) |
false |
If true, only print candidates without deleting |
delete-aliased-versions |
No | boolean (true/false) |
false |
If true, allow deleting alias-referenced versions |
Notes:
- At least one of
keep-latestorolder-than-daysis required. - If both are provided, a version is selected when either condition matches (OR).
$LATESTis never deleted.- For multiple functions, pass
function-nameas a multiline string (newline-separated).
| Name | Type | Description |
|---|---|---|
total-versions |
string (number) | Total number of published versions across all target functions excluding $LATEST |
selected-count |
string (number) | Number of selected deletion candidates |
deleted-count |
string (number) | Number of versions actually deleted |
selected-versions |
string (JSON array) | JSON array of selected versions as objects ([{ "functionName": "...", "version": "..." }]) |
deleted-versions |
string (JSON array) | JSON array of deleted versions as objects ([{ "functionName": "...", "version": "..." }]) |
name: prune-lambda-versions
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
jobs:
prune:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials via OIDC
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/github-actions-oidc-role
aws-region: ap-northeast-1
- name: Prune lambda versions
uses: suzujun/aws-lambda-version-pruner@v1
with:
function-name: |
my-lambda-function-a
my-lambda-function-b
aws-region: ap-northeast-1
keep-latest: "10"
older-than-days: "30"
dry-run: "false"
delete-aliased-versions: "false"