使用SNS电子邮件警报为Elastic Beanstalk创建多个Cloudwatch警报

时间:2017-03-05 05:25:47

标签: amazon-web-services elastic-beanstalk amazon-sns amazon-cloudformation

所以,我一直在互联网上阅读,试图让我运行的Elastic Beanstalk应用程序在指标变坏时向我发送电子邮件。

我知道我可以通过控制台执行此操作,但我想要一种可配置的方法,我可以自动进行多种部署。

我到目前为止(见编辑):

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

如何配置多个警报(环境健康监视器,cpu监视器,延迟监视器)并让他们向我发送电子邮件?

编辑:上面的代码创建了一个与ELB无关的警报。它不会显示在控制台上,而是在完全独立的区域中创建。 :(

1 个答案:

答案 0 :(得分:1)

除警报外,您还需要进一步定义事件路由到的SNS主题。

之后,您可以定义电子邮件订阅,它将接收这些Cloudwatch警报。

这是一个示例CloudFormation模板:

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