Cost Optimization for AWS Lambda3. Fine-tune CloudWatch Logs2 min

Lambda functions use CloudWatch Logs as their default logging destination. This logging includes output from the Lambda service as well as output from your function code. CloudWatch Logs charges for the collection, storage and analysis of data. Customers with unmanaged retention policies and/or overly verbose logging can sometimes accrue unnecessary charges.

Consider your log retention policies. Perhaps development environment logs only need to be retained for a week or less. If production logs remain valuable for longer durations, they can eventually be pushed to lower cost tiers within S3 and removed from CloudWatch entirely. By being attentive to log retention you can reduce your cost of log storage.

You can also reduce logging costs by being attentive to your log output. For example, you may want more verbose logging in pre-production environments, where debugging information is more valuable and your log volume is lower. You may want less verbose logging in production environments where debugging information is less necessary and your log volume is much greater.

Lambda Powertools (available in Python, TypeScript, Java, and .NET) provides structured logging tools that enable you to set log levels that can be configured on a per environment basis.


Created by:

Dan Fox
Dan FoxDan Fox is a Principal Specialist Solutions Architect at AWS. Dan works with customers to help them leverage serverless services to build scalable, fault-tolerant, high-performing, cost-effective applications.
Anton Aleksandrov
Anton AleksandrovAnton Aleksandrov is a Principal Solutions Architect for AWS Serverless and Event-Driven architectures.
Josh Kahn
Josh KahnPrincipal Solution Architect @ AWS.
Dhiraj Mahapatro
Dhiraj MahapatroPrincipal Specialist SA, Serverless, AWS.
Vamsi Vikash Ankam
Vamsi Vikash AnkamSolutions Architect, AWS