1

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. :(

JapanRob
  • 354
  • 3
  • 16

1 Answers1

1

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@example.com"
      Protocol: Email
      TopicArn:
        Ref: AlarmTopic
jens walter
  • 13,269
  • 2
  • 56
  • 54
  • I'll try this tomorrow and report back to you. I don't see anything linking the Cloudwatch Alarm to the Elastic Beanstalk App, or anything linking the TopicSubscriptionArea to the Alarm. Is that a problem? – JapanRob Mar 05 '17 at 12:19
  • I just copied your alarm definition from above. I'm not sure what metrics beanstalk is publishing, but you can adjust the alarm to your metrics. – jens walter Mar 05 '17 at 12:25
  • Thank you. I'll adjust some things and ask around a bit. If I can make this work, I'll accept the answer. – JapanRob Mar 05 '17 at 12:29