aws / aws/aws-cdk

(custom-resources): CustomResourceProvider should destroy log group when stack deleted

Open
#26,553 9 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

@aws-cdk/custom-resources feature-request p3
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 1h
Merged PRs (30d)
74

Description

Describe the feature

Delete Log Groups created by auto-created a CustomResourceProvider when stack is destroyed. These are sometimes an "implementation detail" of constructs like s3.Bucket, so a CDK user may not be aware they need to clean them up.

Use Case

My CDK created an s3.Bucket with autoDeleteObjects: true, and when I destroy the stack, I noticed there was still a CloudWatch Log Group not cleaned up.

[/aws/lambda/XXXXXXXXXXXStack-CustomS3AutoDeleteObjectsCustomRe-xxxxxxxxxxxx

This appears to be a result of the auto-created Log Group for the CustomResourceProvider Lambda. This leaves cruft in the AWS account, which the user didn't intent to create.

Proposed Solution

after the CustomResourceProvider 'AWS::Lambda::Function' is created, also create the "AWS::Logs::LogGroup" and set RemovalPolicy to destroy

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk-lib/core/lib/custom-resource-provider/custom-resource-provider.ts#L307

Other Information

No response

Acknowledgements
  • I may be able to implement this feature request
  • This feature might incur a breaking change
CDK version used

2.88.0 (build 5d497f9)

Environment details (OS name and version, etc.)

macOS 12.6.6

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/aws-cdk-lib/core/lib/custom-resource-provider/custom-resource-provider.ts around the AWS::Lambda::Function creation referenced in the issue. Trace how the CustomResourceProvider is synthesized, then verify that its AWS::Logs::LogGroup is removed when the stack is destroyed. The issue does not name a test file, so inspect nearby provider tests before running the relevant test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.