如何通过CloudFormation配置CloudWatch告警的M/N触发规则?
CloudWatch Alarm M Value Configuration in CloudFormation
Great question! Actually, CloudFormation does support configuring the M value (the number of datapoints that need to breach the threshold) alongside the N value (EvaluationPeriods). The parameter you're looking for is DatapointsToAlarm.
Here's a clear breakdown:
EvaluationPeriods: This is your N, the total number of consecutive evaluation periods CloudWatch checks.DatapointsToAlarm: This is your M, the number of those periods that must breach the threshold to trigger the alarm.
By default, if you don't specify DatapointsToAlarm, it automatically matches the value of EvaluationPeriods (so M=N), which is probably why you didn't spot it initially.
Example CloudFormation Snippet
Resources: HighCPUAlarm: Type: AWS::CloudWatch::Alarm Properties: AlarmName: "EC2-High-CPU-Utilization" MetricName: "CPUUtilization" Namespace: "AWS/EC2" Statistic: Average Period: 300 EvaluationPeriods: 5 # Total evaluation periods (N = 5) DatapointsToAlarm: 3 # Breaches needed to trigger (M = 3) Threshold: 85 ComparisonOperator: GreaterThanThreshold AlarmActions: - !Ref CPUAlarmNotificationTopic
In this example, the alarm will only activate if 3 out of the last 5 5-minute periods show average CPU utilization above 85%—perfect for cutting down on false alarms from temporary metric spikes.
内容的提问来源于stack exchange,提问作者villasv
相关产品推荐
相关产品推荐

