The problem
We have some Lambda Functions
aws lambda list-functions --query "Functions[].FunctionName"
[
"xraystarter-LogRetentionaae0aa3c5b4d4f87b02d85b201-2QZ9sjniwX2i",
"xraystarter-BucketNotificationsHandler050a0587b754-z8E1DEE5a2Zy",
"xraystarter-py",
"xraystarter-go",
"xraystarter-ts"
]
The first time a function writes to stdout/stderr, a Log Group will be created.
aws logs describe-log-groups --query "logGroups[].logGroupName"
"/aws/lambda/hellodockerarm",
"/aws/lambda/xraystarter-BucketNotificationsHandler050a0587b754-z8E1DEE5a2Zy",
"/aws/lambda/xraystarter-LogRetentionaae0aa3c5b4d4f87b02d85b201-2QZ9sjniwX2i",
"/aws/lambda/xraystarter-go",
"/aws/lambda/xraystarter-py",
"/aws/lambda/xraystarter-ts"
]
After deleting all Functions
aws lambda list-functions --query "Functions[].FunctionName"
[]
All log groups are still there:
╰─ aws logs describe-log-groups --query "logGroups[].logGroupName"
[
"/aws/lambda/hellodockerarm",
"/aws/lambda/xraystarter-BucketNotificationsHandler050a0587b754-z8E1DEE5a2Zy",
"/aws/lambda/xraystarter-LogRetentionaae0aa3c5b4d4f87b02d85b201-2QZ9sjniwX2i",
"/aws/lambda/xraystarter-go",
"/aws/lambda/xraystarter-py",
"/aws/lambda/xraystarter-ts"
]
The tool
orphan
shows the leftover "orphaned" Log Groups and with an additional parameter --no-dry-run
it will delete all Log Groups fast. Because it`s GO.
See https://github.com/megaproaktiv/orphan and download the binary release, if you like. Use at your own risk!
bash
orphan
/aws/lambda/hellodockerarm
/aws/lambda/xraystarter-BucketNotificationsHandler050a0587b754-z8E1DEE5a2Zy
/aws/lambda/xraystarter-LogRetentionaae0aa3c5b4d4f87b02d85b201-2QZ9sjniwX2i
/aws/lambda/xraystarter-go
/aws/lambda/xraystarter-py
/aws/lambda/xraystarter-ts
bash
orphan --no-dry-run
Deleted: /aws/lambda/hellodockerarm
Deleted: /aws/lambda/xraystarter-BucketNotificationsHandler050a0587b754-z8E1DEE5a2Zy
Deleted: /aws/lambda/xraystarter-LogRetentionaae0aa3c5b4d4f87b02d85b201-2QZ9sjniwX2i
Deleted: /aws/lambda/xraystarter-go
Deleted: /aws/lambda/xraystarter-py
Deleted: /aws/lambda/xraystarter-ts
bash
aws logs describe-log-groups --query "logGroups[].logGroupName"
[]
More AWS Tools i made to make my life easy
switch
https://github.com/megaproaktiv/switchaws
Working together with leapp or similar sso supporting tools to switch aws profiles and perform other actions when switching the profile
cdkstat
https://github.com/megaproaktiv/cdkstats
Show state of CloudFormation stacks managed by the AWS CDK Cloud Development Kit
Conclusion
If you need consulting for your serverless project, don't hesitate to contact the sponsor of this blog, tecRacer.
For more AWS development stuff, follow me on dev https://dev.to/megaproaktiv.
Thanks to
Photo by Bernardo Ramonfaur on Unsplash
Top comments (0)