AWS SQS
Amazon Simple Queue Service (SQS) is a fully managed message queue. A producer sends messages to the queue and a consumer reads and processes them when it can, so the two parts of an application do not depend on each other being available or running at the same speed.
Key concepts #
- Standard queues: nearly unlimited throughput, at-least-once delivery and best-effort ordering. Consumers must be idempotent.
- FIFO queues: strict order (per message group) and exactly-once processing, with lower throughput.
- Visibility timeout: after a consumer receives a message, it is hidden from the others for some time. If it is not deleted before the timeout ends, it becomes visible again and is retried.
- Dead-letter queue (DLQ): receives the messages that failed too many times, so they can be analyzed without blocking the queue.
- Long polling reduces empty responses and cost; delay queues and message timers postpone delivery.
- Messages up to 256 KB, retained from 1 minute to 14 days. Encrypted at rest with SQS-managed keys or KMS; access with IAM and queue policies.
- Consumers: Lambda (with an event source mapping that scales automatically), EC2 or containers, often scaled with Auto Scaling on the queue length.
- Typically fed by SNS (fan-out) or S3 events.
Pricing #
Per million requests (with a monthly free tier) plus data transfer. See the SQS pricing.
With Terraform #
The resources are aws_sqs_queue, aws_sqs_queue_policy and aws_sqs_queue_redrive_policy.