| description | Docs for the sst.Queue construct in the @serverless-stack/resources package. This construct creates an SQS queue. |
|---|
The Queue construct is a higher level CDK construct that makes it easy to create a SQS Queues. You can create a queue by specifying a consumer function. And then publish to the queue from any part of your serverless app.
This construct makes it easier to define a queue and a consumer. It also internally connects the consumer and queue together.
new Queue(scope: Construct, id: string, props: QueueProps)Parameters
- scope
Construct - id
string - props
QueueProps
import { Queue } from "@serverless-stack/resources";
new Queue(this, "Queue", {
consumer: "src/queueConsumer.main",
});Create an empty queue and lazily add the consumer.
const queue = new Queue(this, "Queue");
queue.addConsumer(this, "src/queueConsumer.main");Allow the consumer function to access S3.
const queue = new Queue(this, "Queue", {
consumer: "src/queueConsumer.main",
});
queue.attachPermissions(["s3"]);Configure the internally created CDK Queue instance.
import { Duration } from "@aws-cdk/core";
new Queue(this, "Queue", {
consumer: "src/queueConsumer.main",
sqsQueue: {
queueName: "my-queue",
visibilityTimeout: Duration.seconds(5),
},
});Configure the internally created CDK Event Source.
new Queue(this, "Queue", {
consumer: {
function: "src/queueConsumer.main",
consumerProps: {
batchSize: 5,
},
},
});Override the internally created CDK Queue instance.
import { Queue } from "@aws-cdk/aws-sqs";
new Queue(this, "Queue", {
consumer: "src/queueConsumer.main",
sqsQueue: Queue.fromQueueArn(this, "MySqsQueue", queueArn),
});An instance of Queue contains the following properties.
Type : cdk.aws-sqs.Queue
The internally created CDK Queue instance.
Type : Function
The internally created consumer Function instance.
An instance of Queue contains the following methods.
addConsumer(scope: cdk.Construct, consumer: FunctionDefinition | QueueConsumerProps)Parameters
- scope
cdk.Construct - consumer
FunctionDefinition | TopicSubscriberProps
Takes FunctionDefinition or QueueConsumerProps object that'll be used to create the consumer for the queue.
Note that, only 1 consumer can be added to a queue.
attachPermissions(permissions: Permissions)Parameters
- permissions
Permissions
Attaches the given list of permissions to the consumerFunction. This allows the consumer to access other AWS resources.
Internally calls Function.attachPermissions.
Type : FunctionDefinition | QueueConsumerProps, defaults to undefined
Takes FunctionDefinition or QueueConsumerProps object used to create the consumer for the queue.
Type : cdk.aws-sqs.Queue | cdk.aws-sqs.QueueProps, defaults to undefined
Or optionally pass in a CDK cdk.aws-sqs.QueueProps or a cdk.aws-sqs.Queue instance. This allows you to override the default settings this construct uses internally to create the queue.
Type : FunctionDefinition
A FunctionDefinition object that'll be used to create the consumer function for the queue.
Type : cdk.aws-lambda-event-sources.lambdaEventSources.SqsEventSourceProps, defaults to undefined
Or optionally pass in a CDK SqsEventSourceProps. This allows you to override the default settings this construct uses internally to create the consumer.