VigilmonAWS SQS Monitoring: Catch Queue Failures Early SQS queues fail silently. Messages pile up...
SQS queues fail silently. Messages pile up and users experience delays with no obvious error.
This tells you how stale your oldest unprocessed message is. If it grows, consumers are not keeping up. Alert when it exceeds 5 minutes.
async function processMessages() {
const { Messages = [] } = await sqs.send(new ReceiveMessageCommand({
QueueUrl: process.env.QUEUE_URL,
MaxNumberOfMessages: 10,
WaitTimeSeconds: 20
}));
for (const msg of Messages) {
const start = Date.now();
try {
await handleMessage(JSON.parse(msg.Body));
await sqs.send(new DeleteMessageCommand({ QueueUrl: process.env.QUEUE_URL, ReceiptHandle: msg.ReceiptHandle }));
console.log(JSON.stringify({ event: 'processed', duration_ms: Date.now() - start }));
} catch (err) {
console.error(JSON.stringify({ event: 'failed', error: err.message }));
}
}
}
Set a CloudWatch alarm on DLQ depth at threshold 1. Any DLQ message is a processing failure.
app.get('/health', async (req, res) => {
const depth = await getQueueDepth();
res.status(depth < 10000 ? 200 : 503).json({ queue_depth: depth });
});
Monitor with Vigilmon.
| Metric | Threshold |
|---|---|
| OldestMessage age | above 5 min |
| DLQ depth | above 0 |
| Consumer health | non-200 |