Skip to content

Conversation

cnaples79
Copy link

Summary

  • Adds explicit dependency between Lambda handler and custom log group in BucketDeployment
  • Prevents log group from being deleted before Lambda completes during stack deletion
  • Resolves issue where deleted log groups were automatically recreated by Lambda

Rationale

When a custom logGroup is provided to BucketDeployment, CloudFormation may delete the log group before the Lambda function finishes executing during stack deletion. This causes AWS Lambda to automatically recreate the log group when it attempts to write logs, resulting in orphaned log groups that appear deleted in CloudFormation but still exist in AWS.

Changes

  • Added handler.node.addDependency(props.logGroup) when a custom log group is provided
  • Ensures the Lambda function is deleted before the log group during stack deletion
  • Follows the same pattern used for VPC dependencies in the construct

Fixes #35632

When a custom log group is passed to BucketDeployment, the log group
was not reliably deleted during stack deletion. This occurred because
there was no explicit dependency between the Lambda function and the
log group.

During stack deletion, CloudFormation could delete the log group before
the Lambda function completed execution. When the Lambda tried to write
logs after the log group was deleted, AWS Lambda automatically recreated
the log group, causing it to remain even after stack deletion.

This change adds an explicit dependency to ensure the Lambda function
is deleted before the log group, preventing the automatic recreation.

Fixes aws#35632
@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p2 beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK labels Oct 1, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team October 1, 2025 04:28
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This review is outdated)

Add test to ensure that when a custom log group is provided to
BucketDeployment, the Lambda function handler has an explicit
dependency on the log group. This prevents the log group from
being deleted before the Lambda during stack deletion.
…ependency

Update the integration test snapshot to reflect the new dependency
between the Lambda function and the custom log group.
Extract log group to a variable to demonstrate the dependency
relationship between the log group and BucketDeployment.
@aws-cdk-automation aws-cdk-automation dismissed their stale review October 1, 2025 05:01

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@cnaples79
Copy link
Author

Updated PR to pass CI linter tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-s3-deployment: custom logGroup of BucketDeployment is prevented from deletion
2 participants