AWS - Prune
The prune command removes old versions of deployed Lambda functions and layers, keeping only the specified number of most recent versions.
serverless prune -n <number>
Options
--numberor-nRequired. Number of previous versions to keep.--stageor-sThe stage to prune.--regionor-rThe region to prune.--functionor-fLimit pruning to a specific function.--layeror-lLimit pruning to a specific layer.--includeLayersor-iInclude layers in pruning.--includeArtifactsor-aAlso mark deployment artifacts that no longer back any function or layer version. Skipped on--function/--layerscoped runs.--dryRunor-dPreview what would be deleted without deleting.--verboseEnable detailed output.
Layer Version Protection
When pruning layers, a layer version that is still attached to an existing version of one of this service's own functions is retained, even if it falls outside the retained --number. This is derived from your local service configuration. Attachments from other services or accounts cannot be detected and remain your responsibility to manage.
Provided lifecycle events
prune:prune
Examples
Keep 3 most recent versions
serverless prune -n 3
Dry-run to preview deletions
serverless prune -n 3 --dryRun --verbose
Prune a specific function
serverless prune -n 5 -f myFunction
Prune including layers
serverless prune -n 3 --includeLayers
Prune only a specific layer
serverless prune -n 3 -l myLayer
Also mark unreferenced deployment artifacts
serverless prune -n 3 --includeArtifacts
See Artifact retention in reference mode for how this interacts with self-managed code storage.