Sub topic 11
Detecting cost anomalies early
Budgets tell you when spend crosses a line you drew in advance. They do not tell you that something unusual started yesterday and is still running. This chapter covers cost anomaly detection: how it differs from budgets, how AWS Cost Anomaly Detection works, how to set it up from the CLI, and how to respond when an alert fires.
It assumes you have read the chapters on cost visibility, tagging and budgets. You should be comfortable running AWS CLI commands and reading JSON.
Why budgets are not enough
A budget compares spend with a fixed number. That has two weaknesses.
- It fires late. With a 1,000 USD monthly budget and an 80 percent alert, a runaway job that costs 50 USD a day takes more than two weeks to trip the alert. By then you have paid for two weeks of waste.
- It is blind to shape. A service that normally costs 5 USD a day and suddenly costs 60 USD a day may still fit inside the total budget. Nothing fires, but something has clearly changed.
An anomaly detector compares spend with what it learned to expect. It looks for deviations from your own historical pattern, so it can flag a small account's 40 USD spike that no fixed threshold would catch.
| Question | Budget | Anomaly detection |
|---|---|---|
| What does it compare against? | A number you chose | A baseline learned from past spend |
| What does it catch well? | Slow drift, total overspend | Sudden spikes, new cost sources |
| Who sets the sensitivity? | You, per budget | The model, plus an impact threshold you choose |
| Typical delay | Days to weeks | Hours to a day |
Use both. Budgets enforce the plan, and anomaly detection catches surprises.
How AWS Cost Anomaly Detection works
AWS Cost Anomaly Detection is a feature of AWS Cost Management. It uses machine learning on your historical spend to model the normal pattern for each segment you ask it to watch. When actual spend for a segment is meaningfully above the expected range, it records an anomaly. The feature itself has no additional charge.
Three objects make up the setup:
- Monitor. Defines what to watch. A monitor can cover each AWS service, each member account, a set of cost allocation tags, or a cost category.
- Subscription. Defines who is told and when. It links one or more monitors to subscribers (email addresses or an Amazon SNS topic), an alert frequency, and an impact threshold.
- Anomaly. A detected event, with a start date, the services, accounts, regions and usage types involved, and an estimated total impact in dollars.
Detection is not instant
Detection runs on billing data, and billing data arrives with a delay. AWS processes cost data several times a day, so an anomaly usually surfaces many hours after the spend began, not within minutes. Cost Anomaly Detection shortens the gap from weeks to about a day. It does not replace real-time controls such as service quotas or CloudWatch alarms on usage metrics for resources that can cost hundreds of dollars per hour.
Choosing monitors
The monitor type decides how finely the detector segments your spend. Finer segments catch smaller problems but produce more alerts.
- AWS services monitor. Watches each service separately, such as EC2, S3 and data transfer. It needs no tags and gives broad coverage. Start here.
- Linked account monitor. Useful in an AWS Organizations setup where each team or environment has its own account. A spike is attributed to the account that caused it.
- Cost allocation tag monitor. Watches spend per tag value, for example one segment for each value of a
teamtag. This is where the tagging work from the earlier chapter pays off. Untagged spend falls outside these segments, which is another reason to keep tag coverage high. - Cost category monitor. Watches the groups you defined in cost categories, such as "production" or "shared platform".
A practical layout is one services monitor for the whole organization plus one monitor per tag key or cost category that maps to an owner. Avoid creating many overlapping monitors. The same spike will appear in each, and people learn to ignore duplicate alerts.
Setting it up from the CLI
First create a monitor that watches each AWS service. The ce namespace hosts both Cost Explorer and Cost Anomaly Detection commands.
aws ce create-anomaly-monitor \
--anomaly-monitor '{
"MonitorName": "all-services",
"MonitorType": "DIMENSIONAL",
"MonitorDimension": "SERVICE"
}'The command returns a MonitorArn. Keep it, because the subscription needs it. You can list monitors again later:
aws ce get-anomaly-monitors \
--query 'AnomalyMonitors[].{Name:MonitorName,Arn:MonitorArn}' \
--output tableNext write the subscription. This one sends a daily email summary of any anomaly with a total impact of at least 100 USD. Replace the ARN and address with your own values.
{
"SubscriptionName": "daily-anomaly-summary",
"MonitorArnList": [
"arn:aws:ce::123456789012:anomalymonitor/EXAMPLE-MONITOR-ID"
],
"Subscribers": [
{ "Type": "EMAIL", "Address": "[email protected]" }
],
"Frequency": "DAILY",
"ThresholdExpression": {
"Dimensions": {
"Key": "ANOMALY_TOTAL_IMPACT_ABSOLUTE",
"MatchOptions": ["GREATER_THAN_OR_EQUAL"],
"Values": ["100"]
}
}
}Save it as subscription.json and create it:
aws ce create-anomaly-subscription \
--anomaly-subscription file://subscription.jsonAlert frequency and delivery
The Frequency field has three values: IMMEDIATE, DAILY and WEEKLY. Immediate alerts are delivered through an SNS topic, while email subscribers receive the daily or weekly summaries. If you want a chat message or a ticket for each anomaly, subscribe an SNS topic and connect it to your chat or ticketing tool.
Choosing a threshold
The threshold filters which detected anomalies reach people. You can filter on absolute impact in dollars (ANOMALY_TOTAL_IMPACT_ABSOLUTE) or on percentage above expected spend (ANOMALY_TOTAL_IMPACT_PERCENTAGE).
- A low threshold, such as 10 USD, catches small problems but creates alert fatigue.
- A high threshold, such as 5,000 USD, protects attention but lets a 4,000 USD problem pass.
- A reasonable starting point is about 1 to 2 percent of monthly spend as an absolute value. Then tune it after a month.
Use a combined expression (absolute and percentage) when a small service can double in cost without ever reaching a meaningful dollar amount. The ThresholdExpression field supports And and Or blocks for this.
Reading an anomaly
Alerts link to the console, but you can also pull anomalies from the CLI, which is useful for scripts and weekly reviews:
aws ce get-anomalies \
--date-interval StartDate=2026-11-01,EndDate=2026-11-26 \
--query 'Anomalies[].{Id:AnomalyId,Start:AnomalyStartDate,Impact:Impact.TotalImpact,Cause:RootCauses[0].Service}' \
--output tableEach anomaly includes RootCauses, a list naming the service, region, account and usage type that contributed most. Use them as your first lead, then confirm with Cost Explorer. Group by USAGE_TYPE for the dates in question, then by tag if tags are present.
Common causes and where to look
Most anomalies come from a small set of events:
- A new or changed workload. A deployment doubled the instance count, or a new feature calls a paid API much more often.
- A runaway process. A retry loop writes millions of small objects to S3, or a job logs far more than before and drives up CloudWatch Logs ingestion.
- Data transfer surprises. A cross-region replication was enabled, or a service started pulling data through a NAT gateway.
- Forgotten experiments. Large instances or GPU nodes left running after a test.
- Legitimate growth. A product launch or traffic spike. This is an anomaly statistically, but not a problem.
Responding to an alert
An alert is only useful if someone owns the next step. A simple triage routine:
- Confirm it is real. Check the dates and amounts in Cost Explorer. Remember that costs can be corrected after the first report.
- Find the owner. Use the tag or account on the root cause to find the team. Untagged spend should go to a named default owner, not nowhere.
- Decide: stop, fix or accept. Stop or resize the resource, fix the code that caused it, or accept it as planned growth.
- Record the outcome. Submit feedback on the anomaly in the console, so the detector's assessment can improve. Note the cause in your team's tracking system, so repeated causes become visible.
Failure modes
- Alert fatigue. Too many monitors or too low a threshold. People mute the channel and miss the real event. Fix by raising the threshold and removing overlapping monitors.
- No owner. Alerts go to a shared inbox that nobody reads. Name a person or rotation in the subscription process.
- Slow ramps. A cost that grows 3 percent a day may look normal to the model at each step. Budgets and monthly trend reviews catch what anomaly detection absorbs.
- Reliance on email only. Email summaries arrive once a day. For fast-moving risks, use SNS with immediate frequency and add usage-based CloudWatch alarms.
Exercise
A team's S3 spend normally runs at 8 USD a day. On Tuesday a bug begins writing many extra objects and the spend rises to 90 USD a day. The account's monthly budget is 3,000 USD with an 80 percent actual-spend alert, and total spend is otherwise steady at about 2,000 USD a month. Which control is likely to flag the problem first, why, and what would you set as the subscription threshold to make sure it reaches a person without creating noise?
Show answer
Cost Anomaly Detection is likely to flag it first. The extra cost is about 82 USD a day, so the monthly total only reaches the 2,400 USD alert line after about five more days. The anomaly detector compares S3 spend with its own learned baseline of 8 USD a day, so it records an anomaly as soon as the billing data shows the jump, typically within a day. A threshold of about 30 to 50 USD absolute impact, which is roughly 1 to 2 percent of the monthly spend, would catch this event while ignoring minor fluctuations. Pair it with a named owner and a daily or immediate delivery method.