aws-sam-cli icon indicating copy to clipboard operation
aws-sam-cli copied to clipboard

Feature request: Prune Old Versions

Open driverpt opened this issue 1 year ago • 4 comments

Describe your idea/feature/enhancement

We should be able to tell SAM CLI to delete AWS Lambda Older Versions (than the ones being deleted) to prevent Resource Excessive Usage.

Proposal

Add a property like:

DeleteOlderVersions: true

Which will set the RetainPolicy of the Version to Delete

We use SnapStart, so we are somehow "protected" against bad versions.

Additional Details

driverpt avatar Aug 23 '24 07:08 driverpt

Thanks for the suggestion @driverpt. I will bring it to the team, but we're always happy to review designs and are open to contributions!

mildaniel avatar Aug 26 '24 20:08 mildaniel

Do you have any suggestions on where to begin?

driverpt avatar Aug 26 '24 20:08 driverpt

The PR: Adds support to delete old versions when successful deployment #7414 enables SAM CLI to automatically clean up previous Lambda function versions after publishing a new version and updating the alias. This cleanup functionality only takes effect when developers use the sam sync command during development to update Lambda function resources.

Would it be valuable to add a flag in SAM templates that modifies the DeletionPolicy for function versions? This would enable CloudFormation deployments to automatically clean up old versions, creating consistent behavior between sam sync and regular CloudFormation deployments."

vicheey avatar Mar 20 '25 19:03 vicheey

Hey, the purpose of my PR was to actually cleanup old versions on sam deploy. The goal is to take advantage of SnapStart and have some sort of Blue-Green Deployment where I don't need to have a separate function to cleanup older versions.

driverpt avatar Mar 21 '25 00:03 driverpt