Consume messages from AWS SQS reliably using visibility timeout, a dead-letter queue, and idempotent processing

domain: aws-sqs · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create a standard or FIFO SQS queue; create a separate dead-letter queue (DLQ) of the same type and configure a redrive policy on the source queue specifying the DLQ ARN and maxReceiveCount (typically 3–5)
  2. Set the queue's VisibilityTimeout to safely exceed your worst-case processing time; if processing can vary, extend visibility mid-flight using ChangeMessageVisibility before the timeout expires
  3. Poll using ReceiveMessage with WaitTimeSeconds up to 20 (long polling) to reduce empty-receive API calls and cost; receive up to 10 messages per call (MaxNumberOfMessages=10)
  4. Process each message and delete it via DeleteMessage using the ReceiptHandle only after successful processing — never delete before confirming success; undeleted messages become visible again after the visibility timeout
  5. Implement idempotency keyed on the message MessageId or a business-level deduplication key stored in a database or ElastiCache; SQS standard queues deliver at least once and occasionally duplicate
  6. Monitor ApproximateNumberOfMessagesNotVisible (in-flight), ApproximateAgeOfOldestMessage, and the DLQ depth in CloudWatch; alert on DLQ depth greater than 0

Known gotchas

Related routes

Redrive messages from an SQS dead-letter queue back to the source queue
aws-sqs · 6 steps · unrated
Fan out SNS messages to multiple SQS queues with subscription filter policies
aws-sns · 6 steps · unrated
Tune SQS visibility timeout and configure a redrive policy
docs.aws.amazon.com · 5 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans