Book a call

Resources · AWS · 2025-09-01

Detecting a Cost Anomaly Before It Becomes a Major Incident: Anonymized AWS Case Study

Stop suffering from budget alerts: learn to turn a cost anomaly into a technical diagnosis. Case study on an AWS recursion loop and the safeguards to prevent it.

Most cloud cost anomalies are not simple "budget variances": they are often the first symptoms of an ongoing technical incident, an architecture drift, an application bug, a processing loop, or a misconfigured observability setup. On AWS, Cost Anomaly Detection identifies these weak signals early enough to trigger an investigation before the bill, or production, explodes.

AWS states that the service uses machine learning to detect abnormal spending, suggest probable causes, and alert teams via email or SNS; it analyzes costs several times a day but relies on Cost Explorer data, which can have up to 24 hours of delay.

In this article, I review an anonymized real case: a cost anomaly detected on AWS uncovered a massive log pipeline runaway, with exploding Lambda invocations, CloudWatch Logs ingestion, Firehose processing, and potential impact on other workloads sharing the same concurrency capacity. The goal is not just to tell the story, but to show how to methodically analyze an anomaly, trace back to the technical root cause (including source code), and what best practices to implement to prevent it.

Why Cost Anomaly Detection is an operations tool, not just financial control

Many teams still perceive anomaly detection as a "budget monitoring" mechanism. This is too reductive. In reality, a cost anomaly is often a direct reflection of a system behavior anomaly:

  • Sudden traffic increase.
  • Log leak or event loop.
  • Uncontrolled scaling or configuration drift.
  • Retry storm or poor resource isolation.

The other key benefit is the first root cause lead provided automatically. AWS allows analyzing anomalies across multiple dimensions (service, account, region, usage type). Instead of starting from "the bill went up", you start from: "this service, in this region, on this usage type, deviated from its expected behavior". This is the pivot that opens the right technical door.

The anonymized case: when a cost anomaly reveals an architecture incident

In this specific case, the FinOps signal revealed a runaway log pipeline involving:

  • CloudWatch Logs (Ingestion).
  • Subscription Filter.
  • Amazon Data Firehose (Transport).
  • Lambda (Transformation).
  • Amazon S3 (Destination).

A cost anomaly is not always a "business" consumption increase. Here, the system responsible for observability had become the major risk. A misconfigured subscription filter can lead to infinite log recursion, with an exponential cost explosion.

Step 1 : Start from the cost signal, not a technical hypothesis

The first discipline is not to jump to conclusions. You must precisely qualify the signal via Cost Explorer:

  • Which service? Which region? Which usage type?
  • Since when and at what rate?
  • Is the gap absolute or relative?

Enabling resource granularity (daily granularity) over the last 14 days is essential here to isolate the responsible identifier.

Step 2 : Translate billing into architecture

The billed service is not always the "business" service causing the behavior. A CloudWatch cost can be triggered by Vended Logs (VPC Flow Logs, WAF, Route 53). You must answer this question: Does this cost correspond to a resource that consumes, or a pipeline that transports, transforms, or stores that consumption?

Step 3 : Immediately correlate with technical metrics

Do technical metrics tell the same story? For a Lambda, monitor:

  • Invocations & Duration.
  • ConcurrentExecutions & Throttles.

A cost spike aligned with technical metrics indicates an active system drift. Reserved concurrency is a critical safeguard here to prevent a drifting function from saturating the entire regional pool of the account.

Step 4 : Precisely map the data flow

In our case, the flow was: Logs → Filter → Firehose → Lambda → S3. Knowing that logs are compressed (gzip) and encoded (base64) before transfer, and that CloudWatch Logs can retry for 24h in case of destination-side error, the pipeline is not a simple pipe but a complex distributed system subject to feedback loops.

Step 5 : Go down to the code (Root Cause)

Some anomalies can only be explained by reading the code. The transformation Lambda decompressed logs but wrote its own verbose application logs. If the log group of this Lambda is within the scope collected by the filter, you create infinite recursion.

Step 6 : Distinguish "pure recursion" from "amplified feedback loop"

The systemic incident often arises from a combination:

  • Over-scoping of collection.
  • Verbose logging in the processor.
  • No concurrency ceiling.
  • Automatic retry mechanisms.

Step 7 : Analysis tools to have in place

  • AWS Cost Anomaly Detection: Create monitors per service and per account with SNS/Email alerts.
  • Cost Explorer (Resource Granularity): Enabled for critical services (available within 48h after activation).
  • CUR + Athena: Essential for deep SQL analysis (Usage type, API Operation).
  • Correlated technical dashboards: Correlate CloudWatch Logs ingestion with Lambda invocations.

Best practices to prevent the anomaly

  1. Explicitly exclude log groups, Use selectionCriteria to exclude log processors from the subscription pipeline.
  2. Avoid Verbose Logging, A processing Lambda should never print(payload) in production.
  3. Reserved Concurrency, Systematically cap non-critical but potentially explosive functions.
  4. Isolate workloads, Do not co-locate critical functions and observability functions in the same concurrency pool.
  5. Adjust Firehose Buffers, Optimize batch sizes to reduce the number of invocations.
  6. Operational alarms, Alert on Throttles and Ingestion before even seeing the cost.

A simple method to remember

A cost anomaly is never just a cost issue; it's an entry point to a technical investigation. The right reaction is not "who increased the bill?", but rather: what behavior changed, in which pipeline, with what amplification, and what safety barriers were missing?

Conclusion

Cost Anomaly Detection is an early incident sensor. Used well, it transforms a financial signal into a technical diagnosis. The case study presented here shows that cost is often the first alert of a deeper problem. Teams that connect FinOps and Cloud Engineering gain a head start on platform reliability.

Take action with KeeFinOps

Want to set up truly actionable cost anomaly detection, and especially know what to do when an alert fires? At KeeFinOps, we help teams connect financial signals, technical diagnosis, and operational remediation, to turn every anomaly into an architecture improvement lever.