How to Automatically Block New AWS Service Operations using SCPs When Your Budget Is Exceeded
Ever worried about accidentally launching expensive AWS resources that blow your budget? This guide shows you how to automatically prevent new AWS operations when your spending reaches certain thresholds. Using AWS's built-in budget and policy features, you can set up automatic "guardrails" that block new services before they can be created.
AWS provides incredible flexibility with 200+ services, but this power comes with risk - a single misconfiguration can result in thousands of dollars in unexpected charges. Whether it's a developer accidentally selecting a c5.24xlarge instance instead of t3.micro (difference: $17,000/month vs $8/month), or automated processes spinning up production-sized resources in development environments, the potential for "bill shock" is real.
This guide solves that dilemma by showing you how to implement proactive cost guardrails using AWS's native budget and policy features. Instead of hoping team members remember cost implications, you'll set up automatic barriers that prevent expensive new resource creation when spending thresholds are reached - while keeping existing services running normally.
Solution Overview
This pattren provides you overview on how to set up automatic cost prevention that works like this:
Normal Operations (Under 80% of budget)
- All AWS services can be created normally
- No restrictions on launching new resources
Warning Level (80% of budget reached)
- Automatically blocks NEW: Large EC2 instances (xlarge, 2xlarge, etc.)
- Automatically blocks NEW: Large storage volumes (over 100GB)
- Still allows NEW: Small instances, essential services, monitoring
- Existing resources: Continue running normally - no interruption
- Sends email: "You've hit 80% of your budget - restrictions on new large resources now active"
Emergency Level (95% of budget reached)
- Automatically blocks NEW: Most compute services (EC2, RDS, Redshift, etc.)
- Still allows NEW: Essential services (monitoring, logging, billing access)
- Existing resources: Continue running normally - no interruption
- Sends email: "Emergency restrictions active - contact admin for overrides to create new resources"
Emergency Override
- Tag specific users/roles to bypass restrictions for critical new resource creation
- Temporary access for urgent business needs
Important Note: This system only prevents creating NEW expensive resources. Your existing EC2 instances, databases, and other services will continue running normally. It's like a spending limit on your credit card - it doesn't cancel existing subscriptions, but prevents new large purchases.
How It Works Behind the Scenes:
- Uses AWS Budgets (tracks your spending)
- Uses AWS Organizations Service Control Policies (blocks new resource creation)
- No custom code or servers needed - all native AWS features
Implementation Guide
Step 1: Create the "Guardrail" Policies
These policies define what new resources get blocked at each spending level. Think of them as different levels of "guardrails" that prevent creating expensive new AWS resources.
Level 1: Moderate Guardrails (80% of budget) Blocks creating new large, expensive resources but allows normal development work
{ "Version": "2012-10-17", "Statement": [ { "Sid": "RestrictLargeInstances", "Effect": "Deny", "Action": "ec2:RunInstances", "Resource": "arn:aws:ec2:*:*:instance/*", "Condition": { "ForAnyValue:StringLike": { "ec2:InstanceType": [ "*.xlarge", "*.2xlarge", "*.4xlarge", "*.8xlarge", "*.16xlarge" ] } } }, { "Sid": "RestrictLargeStorage", "Effect": "Deny", "Action": "ec2:CreateVolume", "Resource": "*", "Condition": { "NumericGreaterThan": { "ec2:VolumeSize": "100" } } } ] }
Level 2: Strong Guardrails (95% of budget) Blocks creating most new services to prevent further spending
{ "Version": "2012-10-17", "Statement": [ { "Sid": "RestrictMostCompute", "Effect": "Deny", "Action": [ "ec2:RunInstances", "rds:CreateDBInstance", "rds:CreateDBCluster", "redshift:CreateCluster", "sagemaker:CreateNotebookInstance" ], "Resource": "*", "Condition": { "StringNotEquals": { "aws:PrincipalTag/EmergencyAccess": "true" } } } ] }
Emergency Lockdown Policy:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "EmergencyLockdown", "Effect": "Deny", "Action": [ "ec2:*", "rds:*", "redshift:*", "sagemaker:*", "elasticmapreduce:*" ], "Resource": "*", "Condition": { "StringNotEquals": { "aws:PrincipalTag/EmergencyOverride": "true" } } }, { "Sid": "AllowEssentialServices", "Effect": "Allow", "Action": [ "cloudwatch:*", "logs:*", "iam:Get*", "iam:List*", "budgets:*" ], "Resource": "*" } ] }
Step 2: Create Budget with SCP Actions
AWS CLI Example:
# Create budget with SCP policy attachment aws budgets create-budget \ --account-id 123456789012 \ --budget '{ "BudgetName": "MonthlyBudgetWithSCP", "BudgetLimit": { "Amount": "1000", "Unit": "USD" }, "TimeUnit": "MONTHLY", "BudgetType": "COST", "CostFilters": { "LinkedAccount": ["123456789012"] } }' \ --notifications-with-subscribers '[ { "Notification": { "NotificationType": "ACTUAL", "ComparisonOperator": "GREATER_THAN", "Threshold": 80, "ThresholdType": "PERCENTAGE" }, "Subscribers": [ { "SubscriptionType": "EMAIL", "Address": "admin@company.com" } ] } ]' # Add SCP policy action for 80% threshold aws budgets create-budget-action \ --account-id 123456789012 \ --budget-name "MonthlyBudgetWithSCP" \ --notification-type "ACTUAL" \ --action-type "APPLY_SCP_POLICY" \ --action-threshold '{ "ActionThresholdValue": 80, "ActionThresholdType": "PERCENTAGE" }' \ --definition '{ "ScpActionDefinition": { "PolicyId": "p-moderate123456", "TargetIds": ["123456789012"] } }' \ --execution-role-arn "arn:aws:iam::123456789012:role/BudgetActionRole" \ --approval-model "AUTOMATIC" \ --subscribers '[ { "SubscriptionType": "EMAIL", "Address": "admin@company.com" } ]' # Add SCP policy action for 95% threshold (emergency) aws budgets create-budget-action \ --account-id 123456789012 \ --budget-name "MonthlyBudgetWithSCP" \ --notification-type "ACTUAL" \ --action-type "APPLY_SCP_POLICY" \ --action-threshold '{ "ActionThresholdValue": 95, "ActionThresholdType": "PERCENTAGE" }' \ --definition '{ "ScpActionDefinition": { "PolicyId": "p-emergency123456", "TargetIds": ["123456789012"] } }' \ --execution-role-arn "arn:aws:iam::123456789012:role/BudgetActionRole" \ --approval-model "AUTOMATIC" \ --subscribers '[ { "SubscriptionType": "EMAIL", "Address": "admin@company.com" } ]'
Step 3: Create IAM Role for Budget Actions
IAM Role Trust Policy:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": "budgets.amazonaws.com" }, "Action": "sts:AssumeRole" } ] }
IAM Policy for SCP Management:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "organizations:AttachPolicy", "organizations:DetachPolicy", "organizations:DescribePolicy", "organizations:ListPolicies" ], "Resource": "*" } ] }
CloudFormation Implementation
AWSTemplateFormatVersion: '2010-09-09' Description: 'SCP Budget Trigger Pattern' Parameters: AccountId: Type: String Description: AWS Account ID to monitor BudgetLimit: Type: Number Default: 1000 Description: Monthly budget limit in USD NotificationEmail: Type: String Description: Email for budget notifications Resources: # SCP Policies ModerateRestrictionPolicy: Type: AWS::Organizations::Policy Properties: Name: BudgetModerateRestriction Description: Moderate cost restrictions for budget enforcement Type: SERVICE_CONTROL_POLICY Content: Version: '2012-10-17' Statement: - Sid: RestrictLargeInstances Effect: Deny Action: ec2:RunInstances Resource: 'arn:aws:ec2:*:*:instance/*' Condition: 'ForAnyValue:StringLike': 'ec2:InstanceType': - '*.xlarge' - '*.2xlarge' - '*.4xlarge' HighRestrictionPolicy: Type: AWS::Organizations::Policy Properties: Name: BudgetHighRestriction Description: High cost restrictions for budget enforcement Type: SERVICE_CONTROL_POLICY Content: Version: '2012-10-17' Statement: - Sid: RestrictMostCompute Effect: Deny Action: - ec2:RunInstances - rds:CreateDBInstance - redshift:CreateCluster Resource: '*' Condition: StringNotEquals: 'aws:PrincipalTag/EmergencyAccess': 'true' # IAM Role for Budget Actions BudgetActionRole: Type: AWS::IAM::Role Properties: RoleName: BudgetActionRole AssumeRolePolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Principal: Service: budgets.amazonaws.com Action: sts:AssumeRole Policies: - PolicyName: BudgetSCPPolicy PolicyDocument: Version: '2012-10-17' Statement: - Effect: Allow Action: - organizations:AttachPolicy - organizations:DetachPolicy - organizations:DescribePolicy - organizations:ListPolicies Resource: '*' # Budget AccountBudget: Type: AWS::Budgets::Budget Properties: Budget: BudgetName: MonthlyAccountBudget BudgetType: COST BudgetLimit: Amount: !Ref BudgetLimit Unit: USD TimeUnit: MONTHLY CostFilters: LinkedAccount: - !Ref AccountId NotificationsWithSubscribers: - Notification: ComparisonOperator: GREATER_THAN NotificationType: ACTUAL Threshold: 80 ThresholdType: PERCENTAGE Subscribers: - Address: !Ref NotificationEmail SubscriptionType: EMAIL # Budget Actions ModerateRestrictionAction: Type: AWS::Budgets::BudgetAction Properties: BudgetName: !Ref AccountBudget ActionType: APPLY_SCP_POLICY ApprovalModel: AUTOMATIC ActionThreshold: ActionThresholdValue: 80 ActionThresholdType: PERCENTAGE Definition: ScpActionDefinition: PolicyId: !Ref ModerateRestrictionPolicy TargetIds: - !Ref AccountId ExecutionRoleArn: !GetAtt BudgetActionRole.Arn HighRestrictionAction: Type: AWS::Budgets::BudgetAction Properties: BudgetName: !Ref AccountBudget ActionType: APPLY_SCP_POLICY ApprovalModel: AUTOMATIC ActionThreshold: ActionThresholdValue: 95 ActionThresholdType: PERCENTAGE Definition: ScpActionDefinition: PolicyId: !Ref HighRestrictionPolicy TargetIds: - !Ref AccountId ExecutionRoleArn: !GetAtt BudgetActionRole.Arn
Best Practices
Policy Design: Create graduated restriction levels that progressively limit expensive operations while maintaining essential functionality.
Emergency Access: Always include emergency override conditions using principal tags for critical business operations.
Monitoring: Set up CloudWatch alarms to monitor budget action executions and SCP attachments.
Testing: Regularly test SCP policies in non-production environments to ensure they work as expected.
Documentation: Maintain clear documentation of all SCP policies and their trigger conditions.
Approval Models: Use AUTOMATIC approval for immediate cost protection, or MANUAL approval for human oversight.
Security Considerations
Least Privilege Access
Ensure the budget action IAM role has minimal permissions:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "organizations:AttachPolicy", "organizations:DetachPolicy" ], "Resource": "*", "Condition": { "StringEquals": { "organizations:PolicyType": "SERVICE_CONTROL_POLICY" } } } ] }
Emergency Override
Include emergency override mechanisms in all restrictive policies:
{ "Condition": { "StringNotEquals": { "aws:PrincipalTag/EmergencyOverride": "true" } } }
Limitations and Considerations
Policy Propagation: SCPs may take several minutes to propagate and take effect across all regions.
Service Coverage: SCPs cannot restrict all AWS actions; some services and operations are not controllable via SCPs.
Emergency Scenarios: Overly restrictive SCPs can block critical operations during emergencies; always maintain override mechanisms.
Billing Delays: AWS billing data may have delays, so budget alerts might not reflect real-time spending.
Manual Removal: SCP policies attached by budget actions must be manually detached when spending decreases.
Conclusion
Using AWS Budgets' native SCP attachment capability provides a simple, effective way to implement automated cost controls without complex infrastructure. This pattern enables organizations to:
- Automatically prevent cost overruns through policy enforcement
- Implement graduated cost control measures based on spending thresholds
- Maintain operational flexibility through emergency override mechanisms
- Achieve immediate cost protection without custom development
The solution is particularly valuable for:
- Organizations with strict cost governance requirements
- Development and testing environments prone to cost overruns
- Multi-account architectures requiring centralized cost control
- Compliance scenarios requiring automated cost guardrails
By leveraging AWS Budgets and Organizations SCPs together, this pattern creates a robust, automated cost governance framework that protects against unexpected spending while maintaining operational flexibility.
- Language
- English
Relevant content
asked 3 years ago
AWS OFFICIALUpdated 7 months ago
AWS OFFICIALUpdated a year ago