Skip to content
Back to Cloud Services

AWS SQS Message Queue

Decouple producers/consumers with managed queues — at-least-once delivery, FIFO ordering, dead-letter queues.

AWSIntermediate

Why

SQS decouples components — producers don't wait, consumers scale independently. 1M requests/mo free, $0.40/M after. FIFO preserves order, DLQ captures failures.

No broker to manage.

When

Use for async work (email, image processing), load leveling, and fan-out. Avoid for pub/sub (use SNS) or streaming (use Kinesis).

How

1. Create queue — aws sqs create-queue --queue-name my-queue 2. Send — aws sqs send-message --message-body '{"job":"resize"}' 3. Receive — aws sqs receive-message --max-number-of-messages 10 4. Delete after process — aws sqs delete-message --receipt-handle <rh> 5. Visibility timeout — message hidden during processing, auto-reappears 6. FIFO — .fifo suffix, ContentBasedDeduplication for exactly-once 7. DLQ — RedrivePolicy moves failed messages after N receives 8. Lambda trigger — SQS → Lambda, batch up to 10 messages

Example

# Create FIFO queue with DLQ aws sqs create-queue --queue-name orders.fifo \ --attributes FifoQueue=true,ContentBasedDeduplication=true # Send message aws sqs send-message \ --queue-url https://sqs.us-east-1.amazonaws.com/123/orders.fifo \ --message-body '{"orderId":"456"}' \ --message-group-id "user-123" # Lambda consumer with partial batch failure export const handler = async (event) => { const failed = []; for (const record of event.Records) { try { await process(JSON.parse(record.body)); } catch (e) { failed.push(record.messageId); } } return { batchItemFailures: failed.map(id => ({ itemIdentifier: id })) }; };

Common Problems

  • ⚠Poison pill messages — set maxReceiveCount on DLQ, investigate DLQ not main queue
  • ⚠FIFO throughput limit — 300 msgs/s per group, 3000/s with batching
  • ⚠Lambda partial batch failure — return batchItemFailures, SQS retries only failed

Best Practices

  • ✓Always set DLQ — captures failures, prevents infinite retries
  • ✓Use FIFO only when needed — Standard is 10x cheaper throughput
  • ✓Batch processing — Lambda receives up to 10 msgs, 10x throughput

FAQ

What is AWS SQS Message Queue and what problem does it solve?

Decouple producers/consumers with managed queues — at-least-once delivery, FIFO ordering, dead-letter queues. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with AWS SQS Message Queue in 5 minutes?

Two steps to run it: (1) Create queue — aws sqs create-queue --queue-name my-queue; (2) Send — aws sqs send-message --message-body '{"job":"resize"}'. Validate on the free tier first, then wire into production.

What is the #1 pitfall with AWS SQS Message Queue?

The most frequent issue is: Poison pill messages — set maxReceiveCount on DLQ, investigate DLQ not main queue. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for AWS SQS Message Queue?

Best practices for AWS SQS Message Queue include: Always set DLQ — captures failures, prevents infinite retries; Use FIFO only when needed — Standard is 10x cheaper throughput; Batch processing — Lambda receives up to 10 msgs, 10x throughput. The first one — "Always set DLQ — captures failures, prevents infinite retries" — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with AWS SQS Message Queue?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most AWS SQS Message Queue options offer a free tier — validate within free quota before scaling.