Skill 4.1.4

Implement custom metrics (for example, Amazon CloudWatch embedded metric format [EMF])

Key Concepts

You can publish custom metrics with the PutMetricData API, choosing a namespace, metric name, dimensions, unit and resolution (standard 60 seconds or high resolution down to 1 second). Calling the API synchronously adds latency and request cost to every invocation.

The embedded metric format (EMF) avoids this: your code writes a JSON log line with a special _aws metadata block, and CloudWatch extracts the metrics from the log asynchronously. EMF works from Lambda, ECS and EC2 (with the CloudWatch agent), and libraries such as Powertools for AWS Lambda produce it for you. Each unique combination of dimensions is a separate metric, so high-cardinality dimensions such as user IDs increase cost.