AWS budget actions
How do I set up AWS budget actions to stop spend at a threshold?
An AWS budget action does one of three things when a budget crosses a threshold: it attaches an IAM policy, attaches a service control policy (SCP), or stops specific EC2 or RDS instances, either automatically or after you approve it. The first two action-enabled budgets are free each month, and each one after that costs $0.10 a day.
The catch is timing. AWS Budgets data updates up to three times a day, typically 8 to 12 hours apart, so an action can fire hours after the spend that crossed the threshold, and it only stops what you pointed it at.
What a budget action can and can't stop
In the API the three types are APPLY_IAM_POLICY, APPLY_SCP_POLICY and RUN_SSM_DOCUMENTS, and one threshold can trigger several actions.
| Action | What AWS does | What keeps running or billing | Limits |
|---|---|---|---|
| Apply an IAM policy | Attaches a managed policy you pick to IAM users, groups or roles | Everything already running; the policy only blocks the calls it denies, for the principals you listed | Up to 100 users, 100 groups and 100 roles |
| Apply an SCP | Attaches an SCP you pick to the accounts you target | Everything already running, and the management account itself | Management account only, up to 100 targets |
| Stop EC2 instances | Stops the instance IDs you list, through Systems Manager | EBS volumes and Elastic IPs keep billing | One Region per action, up to 100 instances, same account only |
| Stop RDS instances | Stops the DB instances you list, through Systems Manager | Storage and backups keep billing, and RDS starts the instance again after 7 days | Not for instances that have a read replica or are one |
An IAM policy or an SCP changes permissions, not resources. AWS describes an SCP as a guardrail that limits what users and roles can do, and its own example deny policy for budget actions stops a user, group or role from provisioning more EC2 resources. Anything already running keeps running and billing. Only the stop actions end compute charges, and only for the instances you list.
SCPs have two more limits. Only the management account can apply them, and they never affect users or roles in the management account itself. The management account can apply an SCP to another account, but it can't stop EC2 or RDS instances in another account.
Set up the IAM role and policies
AWS Budgets runs every action through a service role you create, and that role must be in the same account as the action. Without the right permissions on it, AWS Budgets can't run the action.
- In IAM, create a role with the trust policy below, so only AWS Budgets in your account can assume it. Replace
123456789012with your account ID. - Attach permissions: the AWS managed policy
AWSBudgetsActions_RolePolicyForResourceAdministrationWithSSMfor EC2 and RDS stops only, or AWS's example policy below for all three action types. - Create the policy the action will attach, like the deny policy below, as a customer managed policy.
- In AWS Budgets, create or edit a cost budget. At Configure alerts, choose Add an alert threshold, set an amount or a percentage, and choose Actual or Forecasted.
- Under Attach actions, choose Add Action, select the role, pick the action type and targets, and choose whether it runs automatically.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": { "Service": "budgets.amazonaws.com" },
"Action": "sts:AssumeRole",
"Condition": {
"ArnLike": { "aws:SourceArn": "arn:aws:budgets::123456789012:budget/*" },
"StringEquals": { "aws:SourceAccount": "123456789012" }
}
}
]
}AWS's example permissions policy for a role that handles IAM, SCP, EC2 and RDS actions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ec2:DescribeInstanceStatus",
"ec2:StartInstances",
"ec2:StopInstances",
"iam:AttachGroupPolicy",
"iam:AttachRolePolicy",
"iam:AttachUserPolicy",
"iam:DetachGroupPolicy",
"iam:DetachRolePolicy",
"iam:DetachUserPolicy",
"organizations:AttachPolicy",
"organizations:DetachPolicy",
"rds:DescribeDBInstances",
"rds:StartDBInstance",
"rds:StopDBInstance",
"ssm:StartAutomationExecution"
],
"Resource": "*"
}
]
}A policy for the action to attach. It blocks launching EC2 instances and calling Bedrock models for whoever it is attached to, and an explicit deny overrides any allow they have. AWS notes that denying bedrock:InvokeModel also blocks Converse and StartAsyncInvoke.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "BudgetActionDenyNewSpend",
"Effect": "Deny",
"Action": [
"ec2:RunInstances",
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream",
"bedrock:CreateModelInvocationJob"
],
"Resource": "*"
}
]
}For the wider question of what AWS can and can't cap, see AWS spending limits. For a Bedrock-only setup, see Amazon Bedrock cost control.
Automatic or manual approval
Each action runs one of two ways. Set to run automatically (AUTOMATIC in the API), AWS applies it when Budgets sees the threshold crossed. Set to need approval (MANUAL), it waits under Requires approval until someone runs it. Either way, AWS sends a notification when an action is pending or has run.
- Open the budget's details page and, under Alerts, choose Requires approval.
- Pick the alert and review the action on the Alert details page.
- Select the action, choose Run action, then Yes, I am sure.
To undo a completed action, use the Action history table. A reversed action is not evaluated again for the rest of the budget period unless you choose Reset. The console shows 60 days of action history.
The same setup from the AWS CLI, here stopping one EC2 instance at 100 percent of actual spend, after approval:
aws budgets create-budget-action \
--account-id 123456789012 \
--budget-name monthly-cost \
--notification-type ACTUAL \
--action-type RUN_SSM_DOCUMENTS \
--action-threshold ActionThresholdValue=100,ActionThresholdType=PERCENTAGE \
--definition '{"SsmActionDefinition":{"ActionSubType":"STOP_EC2_INSTANCES","Region":"us-east-1","InstanceIds":["i-1234567890abcdef0"]}}' \
--execution-role-arn arn:aws:iam::123456789012:role/BudgetsActionRole \
--approval-model MANUAL \
--subscribers SubscriptionType=EMAIL,Address=ops@example.comThe 8 to 12 hour delay
Budget actions run on AWS Budgets data, which updates up to three times a day, typically 8 to 12 hours after the previous update. The threshold is only checked against that data, so an action can fire many hours after the spend that crossed it.
That is fine for a slow monthly overrun, but too slow for a runaway Lambda loop or a leaked key launching instances, where the bill grows by the hour. A forecasted threshold fires earlier on steady growth, but a sudden spike still has to reach Budgets data first. For earlier alerts, see AWS billing alerts.
Budgets and their notifications are free. Your first two action-enabled budgets are free each month however many actions they hold, and each one after that costs $0.10 a day.
Where Costbrake fits
Keep a budget action as the automatic backstop; Costbrake covers the hours before Budgets catches up. With the CloudWatch permission it estimates Lambda, Bedrock, NAT gateway and GPU instance spend every few minutes. On Pro and Team it checks every 5 minutes, and every minute for 2 hours after a spike: an hour that costs more than 3 times its 7-day hourly average and at least $5 more. Without it, Costbrake reads only Cost Explorer, every 4 hours, and those figures can run up to 24 hours behind.
Costbrake's AWS brakes throttle a Lambda function to zero, turn off an IAM access key, stop an EC2 instance, or block Bedrock for a role or user with a deny policy. An admin picks the target and confirms; nothing fires on its own. Each brake has an undo that puts back what it changed, such as the function's earlier concurrency. Brakes come with Pro and Team, and setup is on the AWS integration page.
Questions and answers
Do AWS budget actions stop all spending in my account?
No. A stop action stops only the EC2 or RDS instance IDs you list, and their storage keeps billing. An IAM policy or SCP blocks the API calls it denies for the users, groups, roles or accounts you target; anything already running keeps running and billing.
Can an AWS budget action run without my approval?
Yes. If you choose to run the action automatically, or set the approval model to AUTOMATIC in the API, AWS runs it when the threshold is crossed. With manual approval it waits under Requires approval, and AWS notifies you either way.
How quickly does an AWS budget action fire after spend crosses the threshold?
Only as fast as AWS Budgets data updates: up to three times a day, typically 8 to 12 hours apart. A sudden spike can run for hours before the action fires.
How much do AWS budget actions cost?
Budgets and notifications are free. The first two action-enabled budgets are free each month however many actions they hold, and each further action-enabled budget costs $0.10 a day.
Will an AWS budget action keep my RDS database stopped?
Not for long. RDS starts a stopped DB instance by itself after seven consecutive days, and you keep paying for its storage and backups while it is stopped. You also can't stop an instance that has a read replica or is one.
Sources
- Configuring budget actions (AWS)
- Setting up a role for AWS Budgets to run budget actions
- Configuring a budget action
- Reviewing and approving your budget action
- Billing and Cost Management example policies
- AWSBudgetsActions_RolePolicyForResourceAdministrationWithSSM
- create-budget-action (AWS CLI)
- SsmActionDefinition (AWS API Reference)
- Managing your costs with AWS Budgets
- AWS Budgets pricing
- How Amazon EC2 instance stop and start works
- Stopping an Amazon RDS DB instance temporarily
- Service control policies (AWS Organizations)
- Identity-based policy examples for Amazon Bedrock
- Example policies for the Amazon EC2 API
- IAM policy evaluation logic
- CreateBudgetAction (AWS API Reference)
Updated