---
title: "Comment by Derek Murawsky on \"Mastering AWS CDK Aspects\" | Hashnode"
description: "This is awesome, and was a very helpful writeup in helping me understand aspects. Thank you! Unfortunately, the logging solution does not work for existing lamb"
url: "https://hashnode.com/posts/mastering-aws-cdk-aspects/63353bc0697c5665ab7e3ec6/comment/63f93a085ebda1e9aa53d2e4"
---

[Discussion](https://hashnode.com/posts/mastering-aws-cdk-aspects/63353bc0697c5665ab7e3ec6)

Comment [Mastering AWS CDK Aspects](https://hashnode.com/posts/mastering-aws-cdk-aspects/63353bc0697c5665ab7e3ec6)

[Derek Murawsky](https://hashnode.com/@dmurawsky)

[Feb 24, 2023](https://hashnode.com/posts/mastering-aws-cdk-aspects/63353bc0697c5665ab7e3ec6/comment/63f93a085ebda1e9aa53d2e4)

This is awesome, and was a very helpful writeup in helping me understand aspects. Thank you! Unfortunately, the logging solution does not work for _existing_ lambdas because they already have a log group created. I can't think of a good way of handling that other than changing the settings on the lambda function itself. A custom construct might be a better approach for that?

[Derek Murawsky](https://hashnode.com/@dmurawsky)

[Feb 27, 2023](https://hashnode.com/posts/mastering-aws-cdk-aspects/63353bc0697c5665ab7e3ec6/comment/63f93a085ebda1e9aa53d2e4#reply-63fce7d09bc922223b9061a1)

To answer my own question, and for anyone else that runs into this problem, the LogRetention class is the way to go. [docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.a…](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_logs.LogRetention.html) "Creates a custom resource to control the retention policy of a CloudWatch Logs log group. The log group is created if it doesn't already exist." This lets you manage the auto-created ones that already exist as well as create new ones that don't. It goes in cleanly and does the job. :)
