QA plan: spend budgets, alarms and kill switch (#385)
Story: Spend budgets, alarms and kill switch (#385)
Capability: Cost guardrails and observability (#31)
ADRs: RAG021 (spend control); RAG020 (observability)
Runbook: Spend and abuse alerts
Test scope
Section titled “Test scope”| Type | Coverage |
|---|---|
| IaC (plan review) | Bootstrap creates SNS topic rag-sample-alerts with an email subscription to alert_email |
| IaC (plan review) | Budget rag-sample-bedrock-daily: $5, daily, cost filter on the Bedrock service names in bedrock_budget_services, notifications at 80% and 100% actual, subscriber rag-sample-alerts |
| IaC (plan review) | Budget rag-sample-monthly: $40, monthly, no cost filter, notifications at 80% actual and 100% forecast, subscriber rag-sample-alerts |
| IaC (plan review) | Each environment root creates four alarms with alarm and OK actions on rag-sample-alerts: rag-sample-<env>-api-invocations (API Lambda Invocations > 600 in 5 min), rag-sample-<env>-api-errors (API Lambda Errors >= 3 in 5 min), rag-sample-<env>-authorizer-duration (authorizer Duration > 8 s), rag-sample-<env>-db-awake-12h (Aurora ServerlessDatabaseCapacity > 0 for 12 h) |
| Integration (manual, QA) | The email subscription is confirmed and a test message published to rag-sample-alerts arrives |
| Integration (manual, QA) | Both budgets exist with the limits and notifications above |
| Integration (manual, QA) | The daily budget’s actual amount for a closed day with Bedrock usage matches that day’s Bedrock lines in Cost Explorer |
| Integration (manual, QA) | Kill switch rehearsal (OC-4): with the API Lambda’s reserved concurrency at 0, /query fails and the API Lambda’s Invocations stays flat; after restore, make qa-smoke passes |
Entry criteria
Section titled “Entry criteria”- Story #20 (Terraform remote state and bootstrap) complete
- QA environment deployed with the API Lambda and authorizer
bedrock_budget_servicesandalert_emailset ininfra/bootstrap/terraform.tfvars
Exit criteria
Section titled “Exit criteria”terraform planfor bootstrap shows the topic, its subscription and the two budgets with the limits, filters, thresholds and subscriber listed in Test scopeterraform planfor each environment root shows the four alarms with the thresholds listed in Test scope- The
rag-sample-alertssubscription is confirmed and the test notification is received aws budgets describe-budgetsshows both budgets with their limits, andaws budgets describe-notifications-for-budgetshows the thresholds for eachaws cloudwatch describe-alarms --alarm-name-prefix rag-sample-qa-lists the four QA alarms withrag-sample-alertsas alarm and OK action- The daily budget’s actual amount for a closed usage day is non-zero and matches Cost Explorer’s Bedrock spend for that day
- The kill switch rehearsal (OC-4) on QA passes as described in Test scope
Environments
Section titled “Environments”IaC: CI plan review. Integration: manual against QA, following the spend and abuse runbook. Prod alarms verified at Prod deploy time.
Tooling
Section titled “Tooling”Terraform, AWS CLI (aws sns publish, aws budgets describe-budgets, aws budgets describe-notifications-for-budget, aws budgets describe-budget-performance-history, aws cloudwatch describe-alarms, aws lambda put-function-concurrency), make qa-smoke.
How tests are written
Section titled “How tests are written”# Given bootstrap is applied and the subscription confirmed# When a test message is published to the alert topic$topic = terraform -chdir=infra/bootstrap output -raw alert_topic_arnaws sns publish --topic-arn $topic --subject "rag-sample alert test" --message "QA plan test notification."# Then the operator receives the email
# Given the budgets are applied# When each budget's notifications are describedaws budgets describe-notifications-for-budget --account-id <account-id> --budget-name rag-sample-bedrock-dailyaws budgets describe-notifications-for-budget --account-id <account-id> --budget-name rag-sample-monthly# Then the daily budget has ACTUAL at 80 and 100, and the monthly budget has ACTUAL at 80 and FORECASTED at 100
# Given the QA alarms are appliedaws cloudwatch describe-alarms --alarm-name-prefix rag-sample-qa- --query "MetricAlarms[].[AlarmName,Threshold,AlarmActions[0]]"# Then four alarms are listed, each with the rag-sample-alerts ARN
# Given the kill switch is onaws lambda put-function-concurrency --function-name rag-sample-qa-api --reserved-concurrent-executions 0# When /query is called, Then it fails and API Lambda Invocations stays flataws lambda delete-function-concurrency --function-name rag-sample-qa-api# And after restore, make qa-smoke passes- The daily budget filters on Cost Explorer service names, which differ from model IDs. Wrong names produce a budget that reads $0 and never alerts; the Cost Explorer comparison in Exit criteria catches this.
- Budgets refreshes spend up to three times a day, so a daily-budget alert can arrive about 12 hours after the breach.
- An unconfirmed email subscription drops every alert silently.
- Bedrock calls from the QA eval CI role and local ingestion bypass the kill switch; the budgets still count them.
Capability acceptance criteria link
Section titled “Capability acceptance criteria link”Cost guardrails: account spend budgets and per-environment abuse alarms email the operator, and the operator can stop API spend with the kill switch.
© 2026 Benjamin Arunski