Overview
TheSQSQueue construct creates an Amazon SQS queue with optional dead-letter queue, FIFO ordering, and encryption. Use it to decouple producers and consumers in event-driven architectures.
Import
Basic Usage
Using the Messaging Factory
The recommended way to add SQS to a Fjall application is through theMessagingFactory:
Properties
| Property | Type | Default | Description |
|---|---|---|---|
queueName | string | Auto-generated | Queue name |
queueType | "standard" | "fifo" | "standard" | Queue type |
visibilityTimeout | number | 30 | Seconds a message is hidden after being read (0-43200) |
messageRetentionPeriod | number | 345600 (4 days) | Seconds to retain messages (60-1209600) |
receiveMessageWaitTime | number | 0 | Long polling wait time in seconds (0-20) |
maxMessageSize | number | 262144 | Maximum message size in bytes (1-262144) |
deliveryDelay | number | 0 | Delay before message becomes visible in seconds (0-900) |
deadLetterQueue.enabled | boolean | false | Create a dead-letter queue |
deadLetterQueue.maxReceiveCount | number | 3 | Failed deliveries before moving to DLQ (1-1000) |
encryption | "SSE_SQS" | "SSE_KMS" | "NONE" | "SSE_SQS" | Encryption type |
kmsKeyArn | string | — | KMS key ARN (when using SSE_KMS) |
contentBasedDeduplication | boolean | true (FIFO) | Enable content-based deduplication. FIFO only, defaults to true. Ignored for standard queues |
fifoThroughputLimit | "perQueue" | "perMessageGroupId" | "perQueue" | FIFO throughput limit |
deduplicationScope | "queue" | "messageGroup" | "queue" | FIFO deduplication scope |
removalPolicy | "DESTROY" | "RETAIN" | "RETAIN" | What happens on stack deletion |
Methods
| Method | Returns | Description |
|---|---|---|
getQueueUrl() | string | Queue URL |
getQueueArn() | string | Queue ARN |
getQueueName() | string | Queue name |
getQueue() | IQueue | CDK Queue construct |
getDeadLetterQueue() | IQueue | undefined | DLQ construct (if enabled) |
grantSend(grantee) | Grant | Grant permission to send messages |
grantConsume(grantee) | Grant | Grant permission to receive and delete messages |
grantPurge(grantee) | Grant | Grant permission to purge the queue |
grantSendAndConsume(grantee) | Grant | Grant send and consume permissions |
Examples
Standard Queue with DLQ
FIFO Queue
FIFO queues guarantee exactly-once processing and preserve message order:Long Polling
Reduce empty responses and API costs with long polling:KMS Encryption
Connecting to Lambda
Use the Lambda event source integration to process queue messages:CloudFormation Outputs
| Output | Description |
|---|---|
{id}QueueUrl | Queue URL |
{id}QueueArn | Queue ARN |
{id}QueueName | Queue name |
{id}DeadLetterQueueUrl | DLQ URL (if enabled) |
{id}DeadLetterQueueArn | DLQ ARN (if enabled) |
Next Steps
Messaging Factory
Create messaging resources via the factory pattern
Lambda Function
Process queue messages with Lambda