Cost Optimization for AWS Lambda8. Use CloudWatch embedded metric format1 min

Many applications benefit from the publication of custom metrics. These metrics may include business performance indicators, technical performance indicators, or other key information requiring measurement. Publishing custom metrics to CloudWatch is frequently used to accomplish this task. The CloudWatch PutMetricData API call from an AWS SDK is a synchronous request. In other words, if you make this call inside your Lambda function, your function will be blocked while it waits for a response, increasing your function duration and consequently your function cost. There is a better and cheaper way to get this data.

The CloudWatch embedded metric format enables you to embed JSON metrics into your structured log events. After the logs are shipped at the end of each invocation they are processed to find data in EMF format. These data are then published as custom metrics to CloudWatch metrics.


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