未针对 SQS 指标触发 AWS CloudWatch 警报 "NumberOfMessagesReceived"

AWS CloudWatch Alarm not triggered for SQS Metrics "NumberOfMessagesReceived"

我正在尝试在消息发送到 SQS 时触发警报。但是,我看到 CloudWatch 指标表明有消息但没有触发警报。

警报目前也处于INSUFFICIENT_DATA状态。为了测试,我正在通过 boto3 客户端发送消息。

下面是我的 SQSCloudWatch 警报的 CloudFormation 模板

QueueMessageAlarm:
Type: AWS::CloudWatch::Alarm
Condition: AlarmsEnabled
Properties:
  AlarmDescription: "Alarm if queue message is greater than 0"
  AlarmActions:
    - !Ref SampleNotificationTopic
  Namespace: "AWS/SQS"
  MetricName: "NumberOfMessagesReceived"
  Statistic: "Sum"
  Period: "900"
  EvaluationPeriods: "1"
  Threshold: "0"
  ComparisonOperator: "GreaterThanThreshold"
  Dimensions:
    - Name: "QueueName"
    - Value:
        Fn::GetAtt:
          - "KinesisStreamFileQueue"
          - "QueueName"

KinesisStreamFileQueue:
  Type: AWS::SQS::Queue
  Properties:
    QueueName: "StreamQueue"

使用 指标而不是任何 "Received" 指标。

使用 "Received" 指标的缺点是,除非您不断收到消息,否则您很可能会卡在 INSUFFICIENT_DATA 中,从而导致警报问题。

我通过更改警报资源的 Dimensions properties 解决了这个问题。资源需要引用队列的arn,之前是获取它

url
Dimensions:
    - Name: QueueName
      Value: { "Fn::GetAtt": [ "KinesisStreamFileQueue", "QueueName"] }