Queue
Reference doc for the `sst.aws.Queue` component.
The Queue
component lets you add a serverless queue to your app. It uses Amazon SQS.
Create a queue
Make it a FIFO queue
You can optionally make it a FIFO queue.
Add a subscriber
Link the queue to a resource
You can link the queue to other resources, like a function or your Next.js app.
Once linked, you can send messages to the queue from your function code.
Constructor
Parameters
-
name
string
-
args?
QueueArgs
-
opts?
ComponentResourceOptions
QueueArgs
dlq?
Type Input
<
string
|
Object
>
Optionally add a dead-letter queue or DLQ for this queue.
A dead-letter queue is used to store messages that can’t be processed successfully by the
subscriber function after the retry
limit is reached.
This takes either the ARN of the dead-letter queue or an object to configure how the dead-letter queue is used.
For example, here’s how you can create a dead-letter queue and link it to the main queue.
By default, the main queue will retry processing the message 3 times before sending it to the dead-letter queue. You can customize this.
dlq.queue
Type Input
<
string
>
The ARN of the dead-letter queue.
dlq.retry
Type Input
<
number
>
Default 3
The number of times the main queue will retry the message before sending it to the dead-letter queue.
fifo?
Type Input
<
boolean
|
Object
>
Default false
FIFO or first-in-first-out queues are designed to guarantee that messages are processed exactly once and in the order that they are sent.
By default, content based deduplication is disabled. You can enable it by configuring
the fifo
property.
fifo.contentBasedDeduplication?
Type Input
<
boolean
>
Default false
Content-based deduplication automatically generates a deduplication ID by hashing the message body to prevent duplicate message delivery.
transform?
transform.queue?
Type QueueArgs
|
(
args
:
QueueArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the SQS Queue resource.
visibilityTimeout?
Type Input
<
“
${number} minute
”
|
“
${number} minutes
”
|
“
${number} hour
”
|
“
${number} hours
”
|
“
${number} second
”
|
“
${number} seconds
”
>
Default “30 seconds”
Visibility timeout is a period of time during which a message is temporarily invisible to other consumers after a consumer has retrieved it from the queue. This mechanism prevents other consumers from processing the same message concurrently, ensuring that each message is processed only once.
This timeout can range from 0 seconds to 12 hours.
Properties
arn
Type Output
<
string
>
The ARN of the SQS Queue.
nodes
nodes.queue
Type Queue
The Amazon SQS Queue.
url
Type Output
<
string
>
The SQS Queue URL.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource
object in the SDK.
-
url
string
The SQS Queue URL.
Methods
subscribe
Parameters
The function that’ll be notified.subscriber
Input
<
string
|
FunctionArgs
|
“arn:aws:lambda:${string}”
>
Configure the subscription.args?
QueueSubscriberArgs
-
opts?
ComponentResourceOptions
Returns Output
<
QueueLambdaSubscriber
>
Subscribe to this queue.
Add a filter to the subscription.
Customize the subscriber function.
Or pass in the ARN of an existing Lambda function.
static subscribe
Parameters
The ARN of the SQS Queue to subscribe to.queueArn
Input
<
string
>
The function that’ll be notified.subscriber
Input
<
string
|
FunctionArgs
|
“arn:aws:lambda:${string}”
>
Configure the subscription.args?
QueueSubscriberArgs
-
opts?
ComponentResourceOptions
Returns Output
<
QueueLambdaSubscriber
>
Subscribe to an SQS Queue that was not created in your app.
For example, let’s say you have an existing SQS Queue with the following ARN.
You can subscribe to it by passing in the ARN.
Add a filter to the subscription.
Customize the subscriber function.
QueueSubscriberArgs
batch?
Type Input
<
Object
>
Default {size: 10, window: “20 seconds”, partialResponses: false}
Configure batch processing options for the consumer function.
batch.partialResponses?
Type Input
<
boolean
>
Default false
Whether to return partial successful responses for a batch.
Enables reporting of individual message failures in a batch. When enabled, only failed messages become visible in the queue again, preventing unnecessary reprocessing of successful messages.
The handler function must return a response with failed message IDs.
Read more about partial batch responses.
Enable partial responses.
For a batch of messages (id1, id2, id3, id4, id5), if id2 and id4 fail:
This makes only id2 and id4 visible again in the queue.
batch.size?
Type Input
<
number
>
Default 10
The maximum number of events that will be processed together in a single invocation of the consumer function.
Value must be between 1 and 10000.
Set batch size to 1. This will process events individually.
batch.window?
Type Input
<
“
${number} minute
”
|
“
${number} minutes
”
|
“
${number} second
”
|
“
${number} seconds
”
>
Default “0 seconds”
The maximum amount of time to wait for collecting events before sending the batch to the consumer function, even if the batch size hasn’t been reached.
Value must be between 0 seconds and 5 minutes (300 seconds).
filters?
Type Input
<
Input
<
Record
<
string
, any
>
>
[]
>
Filter the records that’ll be processed by the subscriber
function.
You can pass in up to 5 different filter policies. These will logically ORed together. Meaning that if any single policy matches, the record will be processed. Learn more about the filter rule syntax.
For example, if you Queue contains records in this JSON format.
To process only those records where the RequestCode
is BBBB
.
And to process only those records where RecordNumber
greater than 9999
.
transform?
Type Object
Transform how this component creates its underlying resources.
transform.eventSourceMapping?
Type EventSourceMappingArgs
|
(
args
:
EventSourceMappingArgs
,
opts
:
ComponentResourceOptions
,
name
:
string
)
=>
void
Transform the Lambda Event Source Mapping resource.