question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(logs): delete associated log group when stack is deleted

See original GitHub issue

When the log group of a Lambda function is created by the LogRetention custom resource, then those log groups linger after the stack has been deleted. It should be possible to configure the removal policy.

Use Case

Not having hundreds of dead log groups around, created for PR and test deployments.

Proposed Solution

This requires setting the deletionPolicy on the CfnResource, and implementing support for the “Delete” event type in the custom resource itself.

Other

N/A

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:53
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
shishkincommented, Feb 26, 2022

We could add this feature on the LogRetention construct and updating the handler with the Delete event.

Yes, LogRetention needs a RemovalPolicy that when set to DESTROY would delete the log group.

3reactions
greensmithcommented, Jun 22, 2022

Another alternative is changing policies on the role to deny log access , to stop them being created in the first place. e.g. for BucketDeployment, if we’re deploying/destroying multiple dev branches i’d rather not have to worry about going in and tidying up after a destroy than having 99/100 logs saying the zip contents were extracted successfully.

const BucketDeploymentHandler = this.bucketDeployment.node.findChild('CustomResourceHandler') as SingletonFunction;
        BucketDeploymentHandler.addToRolePolicy(new PolicyStatement({
            actions:['logs:*'],
            resources:['*'],
            effect: Effect.DENY
       })
)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Delete Log Group of Lambda Function When You Destroy ...
AWS CDK 2.37 supports “logs: delete associated log group when the stack is deleted.” Motivation. I often scrap and build Lambda functions for...
Read more >
Stack deletion deletes log group but re-creates it on lambda ...
Hello, I have a cloudformation template which defines a lambda, which is invoked by a custom resource.
Read more >
AWS::Logs::LogGroup - AWS CloudFormation
The AWS::Logs::LogGroup resource specifies a log group. A log group defines common properties for log streams, such as their retention and access control ......
Read more >
AWS CloudWatch Log Group Deletion - Elastic
Identifies the deletion of a specified AWS CloudWatch log group. When a log group is deleted, all the archived log events associated with...
Read more >
CloudWatch log group is not deleted on cdk destroy
See https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-logs.LogGroup.html#removalpolicy. You need to set the removalPolicy of the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found