feat: add LogGroup property to AWS::Serverless::Function for stack-managed CloudWatch log groups#3957
Open
GuidoNebiolo wants to merge 5 commits into
Open
feat: add LogGroup property to AWS::Serverless::Function for stack-managed CloudWatch log groups#3957GuidoNebiolo wants to merge 5 commits into
GuidoNebiolo wants to merge 5 commits into
Conversation
…oup property Add a LogGroup property to AWS::Serverless::Function that generates a stack-managed AWS::Logs::LogGroup. By default the group uses the conventional /aws/lambda/<function-name> name (no LoggingConfig or IAM change needed, since the group coincides with Lambda's default destination and AWSLambdaBasicExecutionRole already grants log writes). A custom LogGroupName binds the function via its native LoggingConfig.LogGroup. RetentionInDays is passed through and DeletionPolicy (Delete by default, or Retain) is applied to both DeletionPolicy and UpdateReplacePolicy so the group is deleted with the stack, avoiding orphaned log groups. When absent, output is unchanged for backward compatibility. Refs aws#2665, aws#3791, aws#1216, aws#2057
Cover the default log group name (Mechanism 1), custom log group name with LoggingConfig wiring (Mechanism 2), DeletionPolicy Retain, Condition propagation to the log group, Globals inheritance/override, and the invalid DeletionPolicy error case, across all partitions. Refs aws#2665, aws#3791, aws#1216, aws#2057
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available
Refs #2665, #3791, #1216, #2057
Description of changes
Adds a new
LogGroupproperty toAWS::Serverless::Functionthat generates a stack-managedAWS::Logs::LogGroup, so the log group is created/updated/deleted together with the stack and its retention is configurable.Two naming mechanisms:
LogGroupName): the group uses the conventional/aws/lambda/<function-name>name viaFn::Sub.LoggingConfigis left untouched and no extra IAM is needed — the name coincides with Lambda's default destination andAWSLambdaBasicExecutionRolealready grants log writes.LogGroupName): binds the function via its nativeLoggingConfig.LogGroup, merging with any existingLoggingConfig.Supported sub-properties:
RetentionInDays(pass-through),DeletionPolicy(Deletedefault, orRetain) applied to bothDeletionPolicyandUpdateReplacePolicy, andLogGroupName. Inheritable viaGlobals. When the property is absent, the transform output is unchanged (backward compatible).This makes retention configurable and deletes the log group with the stack, addressing orphaned log groups (#1216).
Description of how you validated changes
DeletionPolicy: Retain,Conditionpropagation, Globals inheritance/override, and an invalidDeletionPolicyerror case.LogGroupresource model and_construct_log_group.make pris green: ruff, mypy --strict, format-check (schema regenerated), full test suite passing with 95.64% coverage.AI usage disclosure
This contribution was developed with the assistance of a generative AI coding tool. All code and tests were reviewed and are fully understood by the author, who is able to answer maintainer questions during review. The generated code was held to the same quality standards as hand-written code, and the diff/tests were kept minimal to ease review.
Checklist