Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWSTemplateFormatVersion: '2010-09-09'
Parameters:
budgetName:
Type: String
emailAddress:
Type: String
Default: ''
budgetAmount:
Type: Number
Default: 50
Conditions:
hasSubscription: !Not [ !Equals [ '', !Ref emailAddress ] ]
Resources:
NotificationTopic:
Type: AWS::SNS::Topic
Properties:
DisplayName: Budgets Notification
TopicName: !Sub '${budgetName}-topic'
EmailSubscription:
Type: AWS::SNS::Subscription
Condition: hasSubscription
Properties:
Endpoint: !Ref emailAddress
Protocol: email
TopicArn: !Ref NotificationTopic
NotificationTopicPolicy:
Type: AWS::SNS::TopicPolicy
Properties:
Topics:
- !Ref NotificationTopic
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: AllowBudgetsPublish
Effect: Allow
Principal:
Service: budgets.amazonaws.com
Action: sns:Publish
Resource: !Ref NotificationTopic
# note that changing some attributes on Budget resources will result in an error.
# this unfortunately is a cloudformation error described here: https://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/365
# workaround is to delete the budget resource and then re-add it.
Budget:
Type: AWS::Budgets::Budget
Properties:
Budget:
BudgetName: !Ref budgetName
BudgetLimit:
Amount: !Ref budgetAmount
Unit: USD
TimeUnit: MONTHLY
BudgetType: COST
CostTypes:
IncludeSupport: false
NotificationsWithSubscribers:
- Notification:
NotificationType: ACTUAL
ComparisonOperator: GREATER_THAN
Threshold: 80
ThresholdType: PERCENTAGE
Subscribers:
- SubscriptionType: SNS
Address: !Ref NotificationTopic
- Notification:
NotificationType: FORECASTED
ComparisonOperator: GREATER_THAN
Threshold: 100
ThresholdType: PERCENTAGE
Subscribers:
- SubscriptionType: SNS
Address: !Ref NotificationTopic
- Notification:
NotificationType: ACTUAL
ComparisonOperator: GREATER_THAN
Threshold: 100
ThresholdType: PERCENTAGE
Subscribers:
- SubscriptionType: SNS
Address: !Ref NotificationTopic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment