
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.