![]() In the AWS Lambda console, choose Create function.Adds delay between log stream deletions to avoid exceeding rate limits.Deletes log stream if the last log ingestion time is greater than configured retention period.Calls the CloudWatch DescribeLogStreams API and gets last log ingestion time.Checks retention day setting for each log group and picks only those log groups that do not have infinite retention setting enabled.The script reads the retention settings for all CloudWatch log groups and clears those log streams that are past their retention day period. Solution overviewĪ simple solution is to run the script provided below (lambda_function.py code) periodically in AWS Lambda. We will setup an AWS Lambda function that can be run on schedule to delete any empty log streams inside CloudWatch log groups. However, CloudWatch will retain the log streams even after logs are emptied by retention period settings. It typically takes up to 72 hours before log events are deleted, but in rare situations might take longer. CloudWatch Logs doesn’t immediately delete log events when they reach their retention setting. You can change the log retention for each log group at any time. Any data older than the current retention setting is deleted. By default, CloudWatch Logs are stored indefinitely, however you can configure how long data is stored in a log group. ![]() Each separate source of logs in CloudWatch Logs makes up a separate log stream. A log stream is a sequence of log events that share the same source. In this post, we will demonstrate process of automating the cleanup of Amazon CloudWatch log streams that have exceeded their retention period. Containerized and auto-scaling workloads (those with short-lived resources that create their own log streams) are common examples of this. While there is no charge for maintaining an empty log stream, having potentially thousands of them can be overwhelming, especially while using the CloudWatch console. ![]() Customers that use Amazon CloudWatch to monitor their applications and resources on AWS can accumulate a large number of log streams that are used only briefly, or are no longer required.
0 Comments
Leave a Reply. |