TERRAFORM · cost-engineering

Terraform: Bedrock budget alerts

An AWS Budgets configuration scoped to Bedrock spend with actual and forecasted alerts to SNS, so agent-driven inference cost gets a tripwire before it becomes a bill surprise.

✓ verified 2026-07-18 · stack: terraform, aws, bedrock · source

Agentic workloads change the shape of inference spend: it arrives in bursts, from automation, on nobody’s screen. AWS Budgets supports cost budgets filtered by the Service dimension (budget filters), which makes a Bedrock-only tripwire a few resources: a monthly budget, an 80% actual alert, and a 100% forecasted alert, both to SNS where your alerting already listens.

budget-bedrock.tf
resource "aws_sns_topic" "cost_alerts" {
name = "bedrock-cost-alerts"
}
# AWS Budgets publishes from its own service principal; the topic policy
# must allow it or notifications silently never arrive.
resource "aws_sns_topic_policy" "cost_alerts" {
arn = aws_sns_topic.cost_alerts.arn
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Sid = "AllowBudgets"
Effect = "Allow"
Principal = { Service = "budgets.amazonaws.com" }
Action = "SNS:Publish"
Resource = aws_sns_topic.cost_alerts.arn
}]
})
}
resource "aws_budgets_budget" "bedrock_monthly" {
name = "bedrock-monthly"
budget_type = "COST"
limit_amount = "200"
limit_unit = "USD"
time_unit = "MONTHLY"
# Scope to Bedrock only: the Service dimension carries the billing
# service name, so EC2 noise never trips this wire.
cost_filter {
name = "Service"
values = ["Amazon Bedrock"]
}
# Tripwire one: real spend crossed 80% of the budget.
notification {
comparison_operator = "GREATER_THAN"
notification_type = "ACTUAL"
threshold = 80
threshold_type = "PERCENTAGE"
subscriber_sns_topic_arns = [aws_sns_topic.cost_alerts.arn]
}
# Tripwire two: the forecast says the month ends over budget. This is
# the one that fires while there is still time to act.
notification {
comparison_operator = "GREATER_THAN"
notification_type = "FORECASTED"
threshold = 100
threshold_type = "PERCENTAGE"
subscriber_sns_topic_arns = [aws_sns_topic.cost_alerts.arn]
}
}

What it does

  • Scopes the budget with the Service cost filter so only Bedrock spend counts against the limit; the rest of the account’s noise cannot mask an inference spike, and an inference spike cannot hide in the total.
  • Splits the alerting job: the ACTUAL 80% alert says “this is really happening”, the FORECASTED 100% alert says “at this rate the month ends over”, which is the earlier and more actionable of the two.
  • Publishes to SNS rather than email, so the alert lands in the same Slack/PagerDuty plumbing as everything else, and the topic policy grants budgets.amazonaws.com publish rights, without which delivery fails silently.
  • Pairs with attribution: a budget says how much, the Bedrock cost attribution artifact says who; together they close the loop the cost engineering pillar argues for. For per-team wires, add a cost_filter on an activated cost allocation Tag (user-prefixed keys) instead of Service.

Failure modes

  • Budgets alert; they do not stop anything. Crossing the limit sends a notification and nothing else. Hard stops need Budget Actions (attaching a restrictive IAM policy) or application-level quota, and automated denial of production inference deserves more thought than an alert threshold.
  • Forecast alerts need history. Early in a month, or on a new account, the forecast is unstable and the FORECASTED alert can fire spuriously or late; the ACTUAL alert is the reliable one in month one.
  • Billing data lags. Budgets evaluates against billing data that updates a few times a day, so a burst can overshoot the 80% line before the alert fires. For same-hour reaction, CloudWatch billing metrics or gateway-level counters are the faster (and coarser) instruments.
  • Member-account scoping. In an Organizations member account, do not filter by linked account (unsupported from within the member); deploy the budget in the account whose spend it watches, or centralise in the payer with per-account filters from there.

Verified against the AWS Budgets filter dimensions (Service, Tag) and notification model at docs.aws.amazon.com/cost-management/latest/userguide/budgets-create-filters.html, 2026-07-18. No AWS resources were created in verification; run terraform plan before any apply.