Cloud Technology

What is the best pattern for publishing custom metrics from a high-volume Lambda function?

AN Asked by Angela Ross · 02-01-2025
0 upvotes 7,570 views 0 comments
The question

I have a Lambda that triggers 500 times per second. I want to track a custom business metric for "RevenuePerInvoke." Should I use the SDK inside the Lambda handler, or will the API latency slow down my execution time too much? Is there a more "serverless" way to do this?

3 answers

0
KI
Answered on 04-01-2025

For high-volume Lambdas, you should strictly avoid using the PutMetricData SDK call inside your handler. It adds significant "cold start" overhead and network latency to every execution, which will increase your Lambda bill. Instead, use the CloudWatch Lambda Insights extension or simply use the AWS Lambda Powertools library to emit metrics using the Embedded Metric Format (EMF). Since EMF just writes to CloudWatch Logs (stdout), it has virtually zero impact on your function's performance. The metrics are then parsed asynchronously by the CloudWatch service in the background.

0
ST
Answered on 05-01-2025

Does using EMF mean you lose the ability to use "High Resolution" metrics, or can the log-based ingestion still handle sub-minute data points?

PA 06-01-2025

Steven, EMF actually supports high-resolution metrics perfectly fine. You just need to specify the "StorageResolution" property in your JSON structure. As long as your logs are being ingested, CloudWatch will treat the extracted data with the same resolution and retention rules as if you had pushed them via the standard API, just without the performance penalty.

0
MI
Answered on 07-01-2025

Another benefit of EMF is that if the CloudWatch API is temporarily down or throttled, your logs still exist, so you won't lose your data points once the service recovers.

AN 08-01-2025

I agree with Michael. Resilience is just as important as cost. Using the logs as a buffer is a much safer architectural pattern for critical financial or operational data.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session