Skip to content

SQS — alert when the dead-letter queue grows

Main SQS queue is processing fine, but the DLQ silently grows — some messages fail 3 attempts and end up there. Nobody looks at the DLQ until it's a thousand deep.

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/sqs-dlq
# */5 * * * * root /opt/sqs-dlq.sh

QUEUE=${DLQ_URL}
REGION=${AWS_REGION:-us-east-1}
THRESH=${THRESH:-10}                  # alert above N messages

DEPTH=$(aws sqs get-queue-attributes \
  --region "$REGION" \
  --queue-url "$QUEUE" \
  --attribute-names ApproximateNumberOfMessages \
  --output text --query 'Attributes.ApproximateNumberOfMessages')

if [ "${DEPTH:-0}" -gt "$THRESH" ]; then
  curl -fsS "$HEARTBEAT_URL" --data "dlq=$DEPTH,threshold=$THRESH"
  exit 2
fi
echo "OK (DLQ=$DEPTH)"

Same thing in Enterno.io

Wire to an Enterno heartbeat — see the daily pattern (DLQ drains at night when someone manually replays) or a sudden jump at release time.

Set up API monitor → ← All recipes

Related recipes