1

你有一个 cloudformation yaml 模板。Cloudwatch 应该在 CPU > 55% 5 分钟时发送电子邮件(例如)。但是没有电子邮件进来。日志中没有错误。模板也执行得很好。

你能帮我找出问题所在吗?

谢谢。

NotificationTopic:
  Type: AWS::SNS::Topic
  Properties:
    TopicName: AlarmTopic
    Subscription:
      - Endpoint: "aws@email.com"
        Protocol: "email"  

WebsiteAutoScalingGroup:
  Type: AWS::AutoScaling::AutoScalingGroup
  Properties:
    LaunchConfigurationName: !Ref WebsiteLaunchConfig
    AvailabilityZones:
      - Fn::Select:
        - 0
        - Fn::GetAZs: !Ref AWS::Region
      - Fn::Select:
        - 1
        - Fn::GetAZs: !Ref AWS::Region
    VPCZoneIdentifier: 
      - !Ref PublicSubnet1CIDR
      - !Ref PublicSubnet2CIDR      
    DesiredCapacity: 1
    MaxSize: 2  
    MinSize: 1  
    TargetGroupARNs:
      - !Ref WebsiteTargetGroup
    NotificationConfigurations:
      TopicARN: !Ref NotificationTopic
      NotificationTypes:
        - 'autoscaling:EC2_INSTANCE_LAUNCH'
        - 'autoscaling:EC2_INSTANCE_LAUNCH_ERROR'
        - 'autoscaling:EC2_INSTANCE_TERMINATE'
        - 'autoscaling:EC2_INSTANCE_TERMINATE_ERROR'

WebsiteScaleUpPolicy:
  DependsOn: WebsiteAutoScalingGroup
  Type: AWS::AutoScaling::ScalingPolicy
  Properties:
    AdjustmentType: ChangeInCapacity
    AutoScalingGroupName: !Ref WebsiteAutoScalingGroup
    Cooldown: '60'
    ScalingAdjustment: 1

CPUAlarmHigh:
  DependsOn: WebsiteAutoScalingGroup
  Type: AWS::CloudWatch::Alarm
  Properties:
    AlarmDescription: Scale-up if CPU > 55% for 5 minutes
    MetricName: CPUUtilization
    Namespace: AWS/EC2
    Statistic: Average
    Period: 300
    EvaluationPeriods: 2
    Threshold: 55
    AlarmActions: 
      - !Ref WebsiteScaleUpPolicy
    Dimensions:
      - Name: AutoScalingGroupName
        Value: !Ref WebsiteAutoScalingGroup
    ComparisonOperator: GreaterThanThreshold
4

0 回答 0