Aws Billing Alarm

Cloudformation configured billing alarms example.

Enabling alarm

Billing > Billing preferences > Activate Receive Billing Alerts feature

Cloudformation

A list of five alarms configured separately vim cloudformation parameters.

Template

AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS Billing alarm configuration. (Alarm activation is MANUAL)'

Parameters:
  Email:
    Type: 'String'
    Description: 'An email that will receive billing alarm notifications.'
    Default: 'example@email.com'
    AllowedPattern: ^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$

  AlarmOne:
    Type: 'String'
    Description: 'Billing alarm #1 value.'
    Default: 500

  AlarmTwo:
    Type: 'String'
    Description: 'Billing alarm #2 value.'
    Default: 1000

  AlarmThree:
    Type: 'String'
    Description: 'Billing alarm #3 value.'
    Default: 1500

  AlarmFour:
    Type: 'String'
    Description: 'Billing alarm #4 value.'
    Default: 2000

  AlarmFive:
    Type: 'String'
    Description: 'Billing alarm #5 value.'
    Default: 10000

Resources:

  BillingAlarmTopic:
    Type: 'AWS::SNS::Topic'
    Properties:
      TopicName: "billing-alarm"
      Subscription:
        - Endpoint: !Ref Email
          Protocol: email

  BillingAlarmOne:
    Type: 'AWS::CloudWatch::Alarm'
    DependsOn: BillingAlarmTopic
    Properties:
      AlarmActions:
        - !Ref BillingAlarmTopic
      AlarmDescription: !Sub 'Notify when estimated billing > ${AlarmOne} USD'
      AlarmName: !Sub 'Estimated billing > ${AlarmOne} USD'
      ComparisonOperator: GreaterThanOrEqualToThreshold
      Dimensions:
        - Name: Currency
          Value: USD
      EvaluationPeriods: 1
      MetricName: EstimatedCharges
      Namespace: AWS/Billing
      Period: 21600
      Statistic: Maximum
      Threshold: !Ref AlarmOne

  BillingAlarmTwo:
    Type: 'AWS::CloudWatch::Alarm'
    DependsOn: BillingAlarmTopic
    Properties:
      AlarmActions:
        - !Ref BillingAlarmTopic
      AlarmDescription: !Sub 'Notify when estimated billing > ${AlarmTwo} USD'
      AlarmName: !Sub 'Estimated billing > ${AlarmTwo} USD'
      ComparisonOperator: GreaterThanOrEqualToThreshold
      Dimensions:
        - Name: Currency
          Value: USD
      EvaluationPeriods: 1
      MetricName: EstimatedCharges
      Namespace: AWS/Billing
      Period: 21600
      Statistic: Maximum
      Threshold: !Ref AlarmTwo

  BillingAlarmThree:
    Type: 'AWS::CloudWatch::Alarm'
    DependsOn: BillingAlarmTopic
    Properties:
      AlarmActions:
        - !Ref BillingAlarmTopic
      AlarmDescription: !Sub 'Notify when estimated billing > ${AlarmThree} USD'
      AlarmName: !Sub 'Estimated billing > ${AlarmThree} USD'
      ComparisonOperator: GreaterThanOrEqualToThreshold
      Dimensions:
        - Name: Currency
          Value: USD
      EvaluationPeriods: 1
      MetricName: EstimatedCharges
      Namespace: AWS/Billing
      Period: 21600
      Statistic: Maximum
      Threshold: !Ref AlarmThree

  BillingAlarmFour:
    Type: 'AWS::CloudWatch::Alarm'
    DependsOn: BillingAlarmTopic
    Properties:
      AlarmActions:
        - !Ref BillingAlarmTopic
      AlarmDescription: !Sub 'Notify when estimated billing > ${AlarmFour} USD'
      AlarmName: !Sub 'Estimated billing > ${AlarmFour} USD'
      ComparisonOperator: GreaterThanOrEqualToThreshold
      Dimensions:
        - Name: Currency
          Value: USD
      EvaluationPeriods: 1
      MetricName: EstimatedCharges
      Namespace: AWS/Billing
      Period: 21600
      Statistic: Maximum
      Threshold: !Ref AlarmFour

  BillingAlarmFive:
    Type: 'AWS::CloudWatch::Alarm'
    DependsOn: BillingAlarmTopic
    Properties:
      AlarmActions:
        - !Ref BillingAlarmTopic
      AlarmDescription: !Sub 'Notify when estimated billing > ${AlarmFive} USD'
      AlarmName: !Sub 'Estimated billing > ${AlarmFive} USD'
      ComparisonOperator: GreaterThanOrEqualToThreshold
      Dimensions:
        - Name: Currency
          Value: USD
      EvaluationPeriods: 1
      MetricName: EstimatedCharges
      Namespace: AWS/Billing
      Period: 21600
      Statistic: Maximum
      Threshold: !Ref AlarmFive