💰 How to Save Money on CloudWatch Using EMF
CloudWatch is great… until your bill makes you question your life choices. If you’re tracking millions of data points, traditional custom metrics can get expensive—fast.
🚨 The Costly Mistake Everyone Makes
Most people use PutMetricData to send each individual datapoint to CloudWatch without aggregation. That means:
❌ You pay for every datapoint you send
❌ Your app makes thousands of extra API calls
What if there was a way to log your metrics instead—for a fraction of the cost?
🚀 Enter Embedded Metric Format (EMF)
Instead of pushing every datapoint as a separate datapoint, you can log structured data in EMF format and let CloudWatch extract metrics automatically.
✅ Storage is cheaper than API calls
✅ Fewer API calls = lower latency
✅ More flexibility (store raw data, analyze later)
🛠️ How to Implement It
The following code is an example metric statement (in Python) for a Lambda function:
print(json.dumps({
"_aws": {
"Timestamp": int(time.time() * 1000),
"CloudWatchMetrics": [
{
"Namespace": “OurCustomStats”,
"Dimensions": [ ["Customer", "Identifier"] ],
"Metrics": [
{
"Name": "Events",
"Unit": "Count"
}
]
}
]
},
"Customer": customer_name,
"Identifier": customer_id,
"Events": float(count)
}))
By switching from direct API calls to EMF logging, you can save your team thousands of dollars while making your application faster.
This is especially game-changing if you’re collecting billions of datapoints—where API costs skyrocket, and every unnecessary request adds latency to your system.
🤔 When NOT to Use EMF
While EMF is awesome for high-volume, cost-sensitive metrics, it’s not a silver bullet. Here are cases where you might want to stick with PutMetricData
:
👉 If you need real-time monitoring: Since EMF metrics are extracted from logs, there’s a delay (usually up to a minute). If you need instant alerts, direct metrics are better.
👉 If you have very few metrics: If your app only tracks a handful of metrics, the savings might not be significant. In that case, the simplicity of PutMetricData
might be worth it.
📚 Learn More
If you’d like to dive deeper into a use-case, take a look at this blog post:
Lowering Costs with CloudWatch EMF
Until next time 👋
— Elsa