简体   繁体   中英

AWS CloudWatch Alarm not triggered for SQS Metrics “NumberOfMessagesReceived”

I am trying to trigger an alarm if message is sent to SQS . However, I see that the CloudWatch metrics indicates that there was a message but no alarm is triggered.

The alarm is currently in INSUFFICIENT_DATA state as well. For testing, I am sending a message via boto3 client.

Below is my CloudFormation Template for SQS and CloudWatch alarm

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"

Use the ApproximateNumberOfMessagesVisible metric instead of any "Received" metric.

The downside of using "Received" metrics is that unless you're constantly receiving messages, you're likely to get stuck in INSUFFICIENT_DATA , resulting in alarm issues.

I figured out the issue by changing the Dimensions properties for the alarm resource. The resource needs to refer to the arn of the queue, and it was previously getting the url of it

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM