Set expiration of CloudWatch Log Group for Lambda Function

Viewed 18852

By default when I create a Lambda function, the CloudWatch Log Group is set to Never Expire. Is it possible to set the expiration (saying 14 days) so I don't have to set it manually from the console after creation?


Updated#1

Thanks to @jens walter answer this is a code snippet of how to solve the problem

Resources:
  LambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      Handler: index.handler
      Runtime: nodejs6.10
      CodeUri: <your code uri>
      Policies: <your policies> 


  LambdaFunctionLogGroup:
    Type: "AWS::Logs::LogGroup"
    DependsOn: "LambdaFunction"
    Properties: 
      RetentionInDays: 14
      LogGroupName: !Join ["", ["/aws/lambda/", !Ref LambdaFunction]]
4 Answers

As of 2021, There is an option to edit retention via console.

cloud watch -> Log Groups -> [your log group] -> actions -> edit retention settings

Related