@aws-cdk/sqs¶
AWS SQS Construct Library¶
Here’s how to add a basic queue to your application:
new Queue(this, 'Queue');
Encryption¶
If you want to encrypt the queue contents, set the encryption
property. You can have
the messages encrypted with a key that SQS manages for you, or a key that you
can manage yourself.
// Use managed key
new Queue(this, 'Queue', {
encryption: QueueEncryption.Managed,
});
// Use custom key
const myKey = new EncryptionKey(this, 'Key');
new Queue(this, 'Queue', {
encryption: QueueEncryption.Kms,
encryptionMasterKey: myKey
});
First-In-First-Out (FIFO) queues¶
FIFO queues give guarantees on the order in which messages are dequeued, and have additional features in order to help guarantee exactly-once processing. For more information, see the SQS manual. Note that FIFO queues are not available in all AWS regions.
A queue can be made a FIFO queue by either setting fifo: true
, giving it a name which ends
in ".fifo"
, or enabling content-based deduplication (which requires FIFO queues).
Reference¶
DeadLetterQueue (interface)¶
-
class
_aws-cdk_sqs.
DeadLetterQueue
¶ Dead letter queue settings
-
queue
¶ The dead-letter queue to which Amazon SQS moves messages after the value of maxReceiveCount is exceeded.
Type: QueueRef
-
maxReceiveCount
¶ The number of times a message can be unsuccesfully dequeued before being moved to the dead-letter queue.
Type: number
-
Queue¶
-
class
_aws-cdk_sqs.
Queue
(parent, name[, props])¶ A new Amazon SQS queue
Extends: QueueRef
Parameters: - parent (
Construct
) – - name (string) –
- props (
QueueProps
or None) –
-
queueArn
¶ The ARN of this queue
Type: QueueArn
(readonly)
-
queueName
¶ The name of this queue
Type: QueueName
(readonly)
-
queueUrl
¶ The URL of this queue
Type: QueueUrl
(readonly)
-
autoCreatePolicy
¶ Controls automatic creation of policy objects. Set by subclasses.
Type: boolean (readonly)
- parent (
QueuePolicy¶
QueuePolicyProps (interface)¶
QueueProps (interface)¶
-
class
_aws-cdk_sqs.
QueueProps
¶ Properties for creating a new Queue
-
queueName
¶ A name for the queue. If specified and this is a FIFO queue, must end in the string ‘.fifo’.
Type: string or None
-
retentionPeriodSec
¶ The number of seconds that Amazon SQS retains a message. You can specify an integer value from 60 seconds (1 minute) to 1209600 seconds (14 days). The default value is 345600 seconds (4 days).
Type: number or None
-
deliveryDelaySec
¶ The time in seconds that the delivery of all messages in the queue is delayed. You can specify an integer value of 0 to 900 (15 minutes). The default value is 0.
Type: number or None
-
maxMessageSizeBytes
¶ The limit of how many bytes that a message can contain before Amazon SQS rejects it. You can specify an integer value from 1024 bytes (1 KiB) to 262144 bytes (256 KiB). The default value is 262144 (256 KiB).
Type: number or None
-
receiveMessageWaitTimeSec
¶ Default wait time for ReceiveMessage calls. Does not wait if set to 0, otherwise waits this amount of seconds by default for messages to arrive. For more information, see Amazon SQS Long Poll.
Type: number or None
-
visibilityTimeoutSec
¶ Timeout of processing a single message. After dequeuing, the processor has this much time to handle the message and delete it from the queue before it becomes visible again for dequeueing by another processor. Values must be from 0 to 43200 seconds (12 hours). If you don’t specify a value, AWS CloudFormation uses the default value of 30 seconds.
Type: number or None
-
deadLetterQueue
¶ Send messages to this queue if they were unsuccessfully dequeued a number of times.
Type: DeadLetterQueue
or None
-
encryption
¶ Whether the contents of the queue are encrypted, and by what type of key. Be aware that encryption is not available in all regions, please see the docs for current availability details.
Type: string or None
-
encryptionMasterKey
¶ External KMS master key to use for queue encryption. Individual messages will be encrypted using data keys. The data keys in turn will be encrypted using this key, and reused for a maximum of dataKeyReuseSecs seconds. The ‘encryption’ property must be either not specified or set to “Kms”. An error will be emitted if encryption is set to “Unencrypted” or “KmsManaged”.
Type: EncryptionKeyRef
or None
-
dataKeyReuseSec
¶ The length of time that Amazon SQS reuses a data key before calling KMS again. The value must be an integer between 60 (1 minute) and 86,400 (24 hours). The default is 300 (5 minutes).
Type: number or None
-
fifo
¶ Whether this a first-in-first-out (FIFO) queue.
Type: boolean or None
-
contentBasedDeduplication
¶ Specifies whether to enable content-based deduplication. During the deduplication interval (5 minutes), Amazon SQS treats messages that are sent with identical content (excluding attributes) as duplicates and delivers only one copy of the message. If you don’t enable content-based deduplication and you want to deduplicate messages, provide an explicit deduplication ID in your SendMessage() call. (Only applies to FIFO queues.)
Type: boolean or None
-
QueueRef¶
-
class
_aws-cdk_sqs.
QueueRef
(parent, name)¶ Reference to a new or existing Amazon SQS queue
Extends: Construct
Abstract: Yes
Parameters: - parent (
Construct
) – The parent construct - name (string) –
-
static
import
(parent, name, props)¶ Import an existing queue
Parameters: - parent (
Construct
) – - name (string) –
- props (
QueueRefProps
) –
- parent (
-
export
() → @aws-cdk/sqs.QueueRefProps¶ Export a queue
Return type: QueueRefProps
-
addToResourcePolicy
(statement)¶ Adds a statement to the IAM resource policy associated with this queue. If this queue was created in this stack (new Queue), a queue policy will be automatically created upon the first call to addToPolicy. If the queue is improted (Queue.import), then this is a no-op.
Parameters: statement ( PolicyStatement
) –
-
queueArn
¶ The ARN of this queue
Type: QueueArn
(readonly) (abstract)
-
queueUrl
¶ The URL of this queue
Type: QueueUrl
(readonly) (abstract)
-
autoCreatePolicy
¶ Controls automatic creation of policy objects. Set by subclasses.
Type: boolean (readonly) (abstract)
- parent (