If you don't set a name for your Lambda functions, AWS will choose one for you based on the following pattern: [stack_name]-[function_name]-[random_hash]
.
The problem is there are certain cases where your Lambda function gets a new name, e.g. if you have to redeploy your stack or if you have renamed the logical resource id of your function.
Then, CloudFormation will associate a new CloudWatch log group with your Lambda function.
In the end, this means you'll have a lot of unused log groups and you might need some time to figure out which one is the most recent one.
Simple use this file as a Lambda function and call it e.g. once a day. Suggestion: Have a separate maintenance stack in your AWS account where you use this function. Then you'll always have a clean set of CloudWatch log groups :-)
Copyright (c) 2018 Sebastian Hesse