CodePark/ questions / CloudWatch, logs & X-Ray
START PRACTICINGPRACTICE
Backend question · Cloud & AWS › CloudWatch, logs & X-Ray

A Lambda function should publish a custom OrdersPlaced metric without adding a synchronous PutMetricData call to every invocation. What is the usual approach?

Write log lines in the CloudWatch Embedded Metric Format, which CloudWatch extracts into metrics

Use the CloudWatch Embedded Metric Format (EMF). EMF is structured JSON that you write to stdout. CloudWatch reads it later and creates metrics from it. So the request path has no extra API call.

"Enable X-Ray, which turns log lines into metrics automatically" is wrong. X-Ray traces requests, but it does not create custom business metrics from logs.


"Increment a counter in a global variable" and "Store counts in
/tmp" are also wrong. Both live in one execution environment only, and the data is lost when Lambda recycles that environment.