Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 169Cloud · AWS

How to get an alert before the AWS bill grows

A forgotten GPU instance, a NAT gateway moving terabytes, a test cluster nobody deleted — cloud bills grow quietly until the invoice arrives. AWS Budgets sends an alert when actual or forecasted cost passes a limit, and Cost Anomaly Detection spots unusual spend. This how-to creates a monthly budget with alerts at 80 % and 100 % (forecast), as Terraform code, and shows how to find what costs the money.

  • 5 Lessen
  • 5 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

169.1

The quick answer

budget.tf
resource "aws_budgets_budget" "monthly" {
  name         = "monthly-total"
  budget_type  = "COST"
  limit_amount = "500"
  limit_unit   = "USD"
  time_unit    = "MONTHLY"
 
  notification {
    comparison_operator        = "GREATER_THAN"
    threshold                  = 80
    threshold_type             = "PERCENTAGE"
    notification_type          = "ACTUAL"
    subscriber_email_addresses = ["cloud-costs@example.com"]
  }
 
  notification {
    comparison_operator        = "GREATER_THAN"
    threshold                  = 100
    threshold_type             = "PERCENTAGE"
    notification_type          = "FORECASTED"
    subscriber_email_addresses = ["cloud-costs@example.com"]
  }
}
terraform apply
aws budgets describe-budgets --account-id 111122223333 --query 'Budgets[].[BudgetName,BudgetLimit.Amount,CalculatedSpend.ActualSpend.Amount]' --output table

169.2

Step by step

  1. One budget per account or team — in an AWS Organization, set budgets in each account (or per cost allocation tag) and one total in the management account.
  2. Two kinds of alerts (quick answer): ACTUAL at 80 % (real money spent) and FORECASTED at 100 % (AWS predicts you will pass the limit this month) — the forecast warns days earlier.
  3. Send alerts where people act — a team mailbox, or an SNS topic to Slack/Teams/ChatOps (subscriber_sns_topic_arns). A personal mailbox of one person is not enough.
  4. Anomaly detection — catches a sudden jump that stays under the budget:
aws ce create-anomaly-monitor --anomaly-monitor '{"MonitorName":"services","MonitorType":"DIMENSIONAL","MonitorDimension":"SERVICE"}'

Then add a subscription (email or SNS) with a minimum impact (for example 50 USD).

  1. Find what costs the money — by service, last 30 days:
aws ce get-cost-and-usage --time-period Start=2026-10-20,End=2026-11-19 --granularity MONTHLY --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE --query 'ResultsByTime[0].Groups[].[Keys[0],Metrics.UnblendedCost.Amount]' --output text | sort -k2 -nr | head
  1. Make costs visible per team — tag everything (team, env, app) with Terraform default_tags, activate the tags as cost allocation tags in the billing console, and filter budgets by tag.
  2. Common quick savings: stop/delete idle instances and old snapshots, right-size instances, VPC endpoints instead of NAT for S3 traffic, lifecycle rules, Savings Plans for steady workloads.

169.3

Check that it worked

describe-budgets lists the budget with its current spend; the subscribers confirmed the email (SNS) and a test alert (lower the threshold briefly) arrives in the team channel.

169.4

Common problems

ProblemCauseFix
No alert though the bill grewAlerts go to a mailbox nobody reads, or not confirmed (SNS).Team channel; confirm subscriptions; test once.
Alert came too lateOnly ACTUAL at 100 %.Add FORECASTED and an ACTUAL alert at 80 %.
AccessDeniedException on budgets/ceIAM role lacks billing permissions.Allow budgets:* / ce:Get* for the finance/ops role.
Costs per team unknownNo tags or tags not activated for billing.Tag resources; activate cost allocation tags.
Budgets show data from yesterdayBilling data updates a few times a day.Normal; anomaly detection and forecasts help.
A runaway resource is still runningBudgets only alert by default.Budget actions (for example apply an SCP) or a runbook to stop resources.

169.5

Go further

1Why add a FORECASTED alert and not only an ACTUAL one?

The forecast warns as soon as AWS predicts you will pass the limit — days before the money is really spent.

2How can each team see its own cloud costs?

Tag resources (team, env, app), activate the tags as cost allocation tags, and filter budgets by tag.

Alle commando's in dit hoofdstuk