- 最新
- 投票最多
- 评论最多
To create an alarm that triggers when a new message arrives in your Dead Letter Queue (DLQ), you should use the ApproximateNumberOfMessagesVisible CloudWatch metric for your DLQ. This metric captures all messages currently available in the DLQ, including those moved due to processing failures from your source SQS queue.
Here's how to set up the alarm:
- Sign in to the AWS Management Console and open the CloudWatch console.
- Choose "Alarms" and then "Create Alarm".
- In the "Select Metric" section, browse for "SQS" metrics.
- Select "Queue Metrics" and find your DLQ by name.
- Choose the
ApproximateNumberOfMessagesVisiblemetric for your DLQ. - In the "Define Alarm" section:
- Set a name and description for your alarm
- Set the threshold to be greater than 0 (or a baseline number if your DLQ normally has some messages)
- Configure the period (e.g., 1 minute)
- Set the evaluation periods and datapoints to alarm (e.g., 1 out of 1)
- Choose the statistic (typically "Sum" for message counts)
- Set up notifications by selecting an existing Amazon SNS topic or creating a new one.
- Create the alarm.
The ApproximateNumberOfMessagesVisible metric is more appropriate than NumberOfMessagesSent because it specifically captures messages that are currently in the queue, including those that were moved to the DLQ as a result of failed processing attempts in your source SQS queue.
Sources
Amazon SNS dead-letter queues - Amazon Simple Notification Service
Creating CloudWatch alarms for Amazon SQS metrics - Amazon Simple Queue Service
If you want to get alerted when a message hits your SQS DLQ, you should monitor the metric:
ApproximateNumberOfMessagesVisible in CloudWatch
This number goes up as soon as a message lands in the DLQ and is waiting to be read. So the moment retries fail on the main queue and the message is moved to DLQ — this value will become 1 (or more).
- What You Should Do
- Open CloudWatch → Alarms → Create Alarm
- Pick the DLQ queue and the metric:
- ApproximateNumberOfMessagesVisible
- Set the threshold like:
- Whenever >= 1
- Optional: for 1 out of 1 evaluation periods (for near instant detection)
- Add an SNS notification (email, Slack, Lambda, etc.)
相关内容
- AWS 官方已更新 7 个月前
