copilot-cli icon indicating copy to clipboard operation
copilot-cli copied to clipboard

Set log retention for custom resources

Open iamhopaul123 opened this issue 3 years ago • 2 comments

Now the logs for custom resources never expire. However, most of them won't make any sense after 30/60 days after deployment. And users need to clean those log groups periodically. It would be great if we can set log retention for custom resource log group by default.

iamhopaul123 avatar Sep 12 '22 16:09 iamhopaul123

@iamhopaul123 any insight into whether this will be prioritized?

rymndhng avatar Feb 13 '24 05:02 rymndhng

Hello @rymndhng !

You can set the Logging configuration of lambda using yaml patch overrides

For example

- op: add
  path: /Resources/EnvControllerFunction/Properties/LoggingConfig
  value:
    ApplicationLogLevel: TRACE
    LogFormat: <optional custom format>
    LogGroup: <custom log group name>
    SystemLogLevel: WARN

And a log group with retention of 30 days.

- op: add
  path: /Resources/EnvControllerLogGroup
  value:
    Type: AWS::Logs::LogGroup
    Properties:
      LogGroupName: !Join ['', [/copilot/, !Ref AppName, '-', !Ref EnvName, '-controller']]
      RetentionInDays: 30

docs: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-lambda-function-loggingconfig.html#cfn-lambda-function-loggingconfig-loggroup

KollaAdithya avatar Feb 19 '24 20:02 KollaAdithya