JapanRob
JapanRob

Reputation: 384

Create Multiple Cloudwatch Alarms for Elastic Beanstalk with SNS Email Alerts

So, I've been reading all around the internet, trying to get my functioning Elastic Beanstalk app to send me an email when a metric goes bad.

I know I can do this via the console, but I want a configurable approach that I can use for multiple deploys automatically.

I have this so far (SEE EDIT):

Resources:
  AWSCloudWatch:
    Type: "AWS::CloudWatch::Alarm"
    Properties:
      ActionsEnabled: true
      AlarmActions: ""
      AlarmDescription: "Traffic spike app over threshold"
      AlarmName: "APP CPU Over 70%"
      ComparisonOperator: GreaterThanOrEqualToThreshold
      EvaluationPeriods: 5
      MetricName: CPUUtilization
      Namespace: Environment Health
      Period: 60
      Statistic: Maximum
      Threshold: 70
      Unit: Percent

How can I configure multiple alarms (environment health monitor, cpu monitor, latency monitor) and have them send me email?

EDIT: The above code creates an alarm that has nothing to do with ELB. It doesn't show up on the console and is instead created in a completely separate area. :(

Upvotes: 1

Views: 1218

Answers (1)

jens walter
jens walter

Reputation: 14069

In addition to the alarm, you need to further define an SNS topic which the event is routed to.

After that, you can define Email subscriptions, which would receive those Cloudwatch alarms.

Here a sample CloudFormation template for that:

AWSTemplateFormatVersion: '2010-09-09'
Resources:
  AlarmTopic:
    Type: AWS::SNS::Topic
  Alarm:
    Type: AWS::CloudWatch::Alarm
    Properties:
      ActionsEnabled: true
      AlarmActions:
        - Ref: AlarmTopic
      AlarmDescription: "Traffic spike app over threshold"
      AlarmName: "APP CPU Over 70%"
      ComparisonOperator: GreaterThanOrEqualToThreshold
      EvaluationPeriods: 5
      MetricName: CPUUtilization
      Namespace: Environment Health
      Period: 60
      Statistic: Maximum
      Threshold: 70
      Unit: Percent
  TopicSubscription:
    Type: AWS::SNS::Subscription
    Properties:
      Endpoint: "[email protected]"
      Protocol: Email
      TopicArn:
        Ref: AlarmTopic

Upvotes: 1

Related Questions