Should Lambda Custom Metrics Use EMF Logs or Synchronous CloudWatch Calls?

For a Lambda handler that calls an AI API, custom telemetry should not become another synchronous service call the handler waits on merely to record what happened. Prefer emitting custom metrics through Embedded Metric Format (EMF) logs over synchronous CloudWatch API calls on the request path. That is the recommendation in AWS’s Lambda best practices, “Metrics and alarms”.

The decision here is how to emit the metrics you already collect—not which model to call, which business metrics to add, or which alarm thresholds to choose.

What changes with EMF?

AWS recommends emitting metrics asynchronously through the function’s logs instead of making synchronous calls to CloudWatch. Applied to an AI API wrapper, this separates the choice of telemetry delivery from the upstream inference request: the handler should not need a separate synchronous CloudWatch call solely to emit its custom metrics.

AWS describes this approach as reducing latency and improving performance. Treat that as architectural guidance, not a promised number of milliseconds saved in your handler. It does not establish zero logging overhead or immediate metric availability.

The same section says Powertools for AWS Lambda’s Metrics utility handles EMF formatting automatically, with links for Python, TypeScript, Java and .NET. Start with the documentation for your runtime and installed version; the presence of those links is not proof of identical APIs or feature parity. Ordinary structured JSON logging is not, by itself, the validation target: check the EMF metric records and the resulting metrics.

A bounded rollout check

My suggested validation sequence is:

  1. Locate the existing emission path. Identify whether the handler waits for a synchronous CloudWatch call solely for custom metrics. Keep the metric definitions unchanged while evaluating the replacement.
  2. Use a runtime-matched EMF implementation. If Powertools fits the application, use its Metrics utility and check that runtime’s setup and emission instructions before changing the handler.
  3. Verify the log side. Run controlled invocations with known metric values and inspect the emitted EMF records. A successful AI API response alone does not prove telemetry was emitted correctly.
  4. Verify the metric side separately. Confirm that the intended metrics appear in CloudWatch with the expected values for those test invocations. A log record is not sufficient evidence that extraction worked, and this guidance does not promise immediate visibility.
  5. Measure request-path behavior. Compare handler timing under comparable inputs and upstream conditions, and confirm the synchronous metric call is no longer on that path. Do not attribute a faster run to EMF if the upstream AI request also changed.

Stop the rollout if you cannot verify the emitted records or resulting metrics. Investigate the runtime’s formatting and emission setup before expanding the change. If metrics appear but handler timing does not improve, report those as separate results rather than declaring the telemetry migration a latency win.

The practical acceptance criterion is two-part: custom metrics are observable through the new path, and the handler no longer waits on a synchronous CloudWatch call just to emit them. Neither result, on its own, proves a delivery guarantee or a measured performance improvement.

I would add a regression check for the handler’s error paths, not just a successful inference response. Replacing the metrics emitter should not silently change what the caller receives when the upstream request fails.

For a small test harness, keep the existing metric definitions and exercise three controlled cases: an upstream success, an upstream error, and a locally simulated timeout. For each case, compare the old and proposed implementations against two separate expectations:

  • Application behavior: the same return value or propagated exception, with no additional synchronous CloudWatch call solely for custom metrics.
  • Telemetry behavior: the metric values that the existing instrumentation intends to record for that case actually reach the emission boundary. Then use controlled deployed invocations to check the EMF records and extracted CloudWatch metrics separately.

I would also inject a failure into the local metrics-emitter abstraction and explicitly test the intended policy: should a telemetry failure replace the upstream result, or should the handler preserve that result? That is an application decision to document, not something to infer from switching to EMF.

This is a proposed regression suite, not a claim about Powertools exception handling or guaranteed delivery. AWS’s EMF recommendation supports changing the emission mechanism; preserving the handler’s success and failure contract still needs its own test.