Skip to content

Instantly share code, notes, and snippets.

@bahrmichael
Created February 2, 2022 16:09
Show Gist options
  • Save bahrmichael/e3ff88b2e31e3eb9f4c019d872983594 to your computer and use it in GitHub Desktop.
Save bahrmichael/e3ff88b2e31e3eb9f4c019d872983594 to your computer and use it in GitHub Desktop.
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