Skip to content

Instantly share code, notes, and snippets.

@stekern
Created April 10, 2023 09:49

Revisions

  1. stekern created this gist Apr 10, 2023.
    45 changes: 45 additions & 0 deletions cfn-monthly-budget.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # NOTE: In order for IAM users and roles to have access to AWS billing and cost management,
    # you'll first need to activate IAM access using your AWS root user. You can follow the guide
    # at the link below if you haven't already configured this.
    # https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_billing.html?icmpid=docs_iam_console#tutorial-billing-step1

    AWSTemplateFormatVersion: 2010-09-09
    Description: |
    Creates an AWS Budgets Budget that notifies you by email once you're on track to exceed the monthly budget."
    Parameters:
    Email:
    Type: String
    Description: "An email address to send budget notifications to."
    Budget:
    Type: String
    Default: "50"
    Description: "The monthly budget in USD."
    Resources:
    MonthlyBudget:
    Type: AWS::Budgets::Budget
    Properties:
    Budget:
    BudgetLimit:
    Amount: !Ref Budget
    Unit: USD
    BudgetType: COST
    TimeUnit: MONTHLY
    TimePeriod:
    Start: "1225864800"
    NotificationsWithSubscribers:
    - Notification:
    ComparisonOperator: GREATER_THAN
    NotificationType: ACTUAL
    Threshold: 80
    ThresholdType: PERCENTAGE
    Subscribers:
    - SubscriptionType: EMAIL
    Address: !Ref Email
    - Notification:
    ComparisonOperator: GREATER_THAN
    NotificationType: FORECASTED
    Threshold: 100
    ThresholdType: PERCENTAGE
    Subscribers:
    - SubscriptionType: EMAIL
    Address: !Ref Email