Feature: Support for `RetentionInDays` and `Retain` in `LoggingConfig` for `AWS::Serverless::Function`

Author: aler95Created Jul 3, 2025Updated Jul 20, 2026
Labelstype/featurestage/needs-feedbackcontributors/welcome

Description:

Currently, when defining a AWS::Serverless::Function, there is no native way to configure the retention period of the associated CloudWatch Log Group. The only available workaround is to manually create a corresponding AWS::Logs::LogGroup resource with a matching name and desired retention period. This adds complexity and creates potential deployment issues (e.g., log group already existing or being created out of order).

It would be beneficial to support log group retention directly in the LoggingConfig property of the AWS::Serverless::Function resource.


Proposed Solution:

Extend the LoggingConfig property to support the following fields:

yaml
MyFunction:
  Type: AWS::Serverless::Function
  Properties:
    LoggingConfig:
      RetentionInDays: 7        # Optional: number of days to retain logs (default: none/infinite)
      Retain: true              # Optional: preserve log group on resource deletion (default: false)

Source: aws/serverless-application-model