One of the fundamental characteristics of the cloud is metered billing: You only pay for what you actually use. In general, this a great concept because the costs scale according to your actual usage of the resources. This is especially useful when experimenting with new stuff or when your application only has a few users. On the other side, you might only know your spending at the end of the billing period. Of course you can regularly check the billing dashboard to have an eye on your spending. But you have better things to do, right?
Therefore, it would be great to be notified automatically once your spending exceeds certain thresholds. You might be able to do things once you budget is exceeded. At least you know that you might pay more than you initially expected.
Exceeding the budget might also indicate that something unintentional happens. For example, your developers are using services which they should not use because they are too expensive. Or maybe a bug in your infrastructure or application code causes a higher consumption than you initially estimated.
For this scenario AWS provides the Budget feature as part of the Cost Management service. Basically, you can create various budgets for all kinds of things going on in your accounts. Whenever the current spending crosses some predefined thresholds a message can be send. The message can either be send via email to a list of subscribers or as a notification to a SNS topic. Based on the SNS notification you can do all kinds of things. For example, you could stop any resources which are not essential, e.g. some EC2 instances which have a certain tag.
The most simple thing is to create a budget which sends an email once a threshold is exceeded. You can configure this manually based on the documentation provided by AWS. If you want to manage various accounts or want to create different kinds of budgets, it might make more sense to add little bit of automation by using CloudFormation. The following CloudFormation template sets up a very basic budget for the account it is created in:
AWSTemplateFormatVersion: 2010-09-09 Parameters: Limit: Type: Number Description: The amount of budget (in USD) per month MinValue: 0 Default: 100 Threshold: Type: Number Description: The threshold at which a notification is sent MinValue: 0 MaxValue: 100 Default: 80 SubscriberAddress: Type: String Description: The email address to which notifications will be sent Resources: MonthlyBudget: Type: AWS::Budgets::Budget Properties: Budget: BudgetLimit: Amount: Ref: Limit Unit: USD BudgetType: COST TimeUnit: MONTHLY NotificationsWithSubscribers: - Notification: Threshold: Ref: Threshold ThresholdType: PERCENTAGE NotificationType: ACTUAL ComparisonOperator: GREATER_THAN Subscribers: - SubscriptionType: EMAIL Address: Ref: SubscriberAddress
This budget sends an email to the configured
SubscriberAddress once the
Limit actually exceeds a
Threshold. With the default values for
Threshold the notification is sent once the monthly costs exceed $80 (80% or $100).
Budgets can be configured for all kinds of things. With the
CostFilter attribute of the
Budget property it can be applied to costs occurring in a linked account, a certain region, for a service or a tag. The available budget filters can be found in the documentation.
Budgets help you to keep an eye on your spending in AWS. Based on the settings of the budget you can get notified whenever your budget is about to be exceeded. This helps you to be prepared for the monthly bill or take corrective actions to lower the costs if necessary and feasible.