I want to trigger a AWS cloudwatch
alarm every time a message is added to my DLQ. I am using cloud formation to deploy my sqs/dlq resource and I can't figure out how to configure this type of alarm.

- 1,897
- 2
- 17
- 31
-
You should have a process for processing items in your DLQ. This might be useful: https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/set-cloudwatch-alarms-for-metrics.html. The metric you’re probably looking for is NumberOfMessagesSent; https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-available-cloudwatch-metrics.html – hephalump Oct 30 '19 at 01:04
-
@hephalump thanks! we will begin to consume the dlq at some point. – Tzvetlin Velev Nov 07 '19 at 00:17
1 Answers
You need to use NumberOfMessagesSent when configuring the alarm. See the refernce in CloudFormation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cloudwatch-alarm.html Here is my solution. This will raise an alarm for each message, but the alarm state will not clear if errors keep occurring in your period. If the alarm state doesn't clear, it will prevent the future notifications. So I wouldn't make the period too long.
Also note, that if you are not manually adding the message to the queue then you will need another solution.
AWS Documentation: If you send a message to a dead-letter queue manually, it is captured by the NumberOfMessagesSent metric. However, if a message is sent to a dead-letter queue as a result of a failed processing attempt, it isn't captured by this metric. Thus, it is possible for the values of NumberOfMessagesSent and NumberOfMessagesReceived to be different.
A solution is outlined in this question which is more vague but similar Configure SQS Dead letter Queue to raise a cloud watch alarm on receiving a message
DLQthresholdAlarm:
Type: AWS::CloudWatch::Alarm
Properties:
AlarmDescription: "Alarm dlq messages when we have 1 or more failed messages in 10 minutes"
Namespace: "AWS/SQS"
MetricName: "NumberOfMessagesSent"
Dimensions:
- Name: "QueueName"
Value:
Fn::GetAtt:
- "MyDeadLetterQueue"
- "QueueName"
Statistic: "Sum"
Period: 300
DatapointsToAlarm: 1
EvaluationPeriods: 2
Threshold: 1
ComparisonOperator: "GreaterThanOrEqualToThreshold"
AlarmActions:
- !Ref MyAlarmTopic