What is the best approach to clean up old lambda versions?

Viewed 1172

I have lambda versions enabled in my CFN template. Over the time, I see that versions are incrementing, and now it consumes code storage space allocated by AWS.

I would like to know what is the best approach to remove old versions. i.e. I just want to keep current version and one before that, remaining all should be deleted.

Option-1:

Option-2 (not sure if this is possible or not)

  • CFN solution
    • i.e. I use AutoPublishAlias attribute to enable lambda versions like below. Is there a way to limit versions in the template itself?
  Type: AWS::Serverless::Function
  Properties:
    AutoPublishAlias: $LATEST
    Handler: yourHandler.handler
    FunctionName: !Sub "YOUR-FUNCTION-NAME"
    CodeUri: dist
    Events:
      healthGet:
        Type: Api
        Properties:
          Path: /YOUR-FUNCTION-NAME
          Method: GET
0 Answers
Related