هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
The quick answer
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"]
}
}Step by step
- 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.
- 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.
- 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. - 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).
- 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- Make costs visible per team — tag everything (
team,env,app) with Terraformdefault_tags, activate the tags as cost allocation tags in the billing console, and filter budgets by tag. - 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.
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.
Common problems
| Problem | Cause | Fix |
|---|---|---|
| No alert though the bill grew | Alerts go to a mailbox nobody reads, or not confirmed (SNS). | Team channel; confirm subscriptions; test once. |
| Alert came too late | Only ACTUAL at 100 %. | Add FORECASTED and an ACTUAL alert at 80 %. |
AccessDeniedException on budgets/ce | IAM role lacks billing permissions. | Allow budgets:* / ce:Get* for the finance/ops role. |
| Costs per team unknown | No tags or tags not activated for billing. | Tag resources; activate cost allocation tags. |
| Budgets show data from yesterday | Billing data updates a few times a day. | Normal; anomaly detection and forecasts help. |
| A runaway resource is still running | Budgets only alert by default. | Budget actions (for example apply an SCP) or a runbook to stop resources. |
Go further
- Command pages: aws, terraform.
- Next how-tos: See who did what in AWS with CloudTrail, Log in to AWS with SSO, Log in to Azure and choose a subscription.
- Learn it: AWS Solutions Architect Pro — start here, AZ-104 — Costs. Full guide: AWS CLI.
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.