class Queue (construct)
This page is available in another version. Click here for the v2 documentation.
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.SQS.Queue |
Java | software.amazon.awscdk.services.sqs.Queue |
Python | aws_cdk.aws_sqs.Queue |
TypeScript (source) | @aws-cdk/aws-sqs » Queue |
Implements
IConstruct
, IConstruct
, IDependable
, IResource
, IQueue
A new Amazon SQS queue.
Example
// An sqs queue for unsuccessful invocations of a lambda function
import * as sqs from '@aws-cdk/aws-sqs';
const deadLetterQueue = new sqs.Queue(this, 'DeadLetterQueue');
const myFn = new lambda.Function(this, 'Fn', {
runtime: lambda.Runtime.NODEJS_14_X,
handler: 'index.handler',
code: lambda.Code.fromInline('// your code'),
// sqs queue for unsuccessful invocations
onFailure: new destinations.SqsDestination(deadLetterQueue),
});
Initializer
new Queue(scope: Construct, id: string, props?: QueueProps)
Parameters
- scope
Construct
- id
string
- props
Queue
Props
Construct Props
Name | Type | Description |
---|---|---|
content | boolean | Specifies whether to enable content-based deduplication. |
data | Duration | The length of time that Amazon SQS reuses a data key before calling KMS again. |
dead | Dead | Send messages to this queue if they were unsuccessfully dequeued a number of times. |
deduplication | Deduplication | For high throughput for FIFO queues, specifies whether message deduplication occurs at the message group or queue level. |
delivery | Duration | The time in seconds that the delivery of all messages in the queue is delayed. |
encryption? | Queue | Whether the contents of the queue are encrypted, and by what type of key. |
encryption | IKey | External KMS master key to use for queue encryption. |
fifo? | boolean | Whether this a first-in-first-out (FIFO) queue. |
fifo | Fifo | For high throughput for FIFO queues, specifies whether the FIFO queue throughput quota applies to the entire queue or per message group. |
max | number | The limit of how many bytes that a message can contain before Amazon SQS rejects it. |
queue | string | A name for the queue. |
receive | Duration | Default wait time for ReceiveMessage calls. |
removal | Removal | Policy to apply when the queue is removed from the stack. |
retention | Duration | The number of seconds that Amazon SQS retains a message. |
visibility | Duration | Timeout of processing a single message. |
contentBasedDeduplication?
Type:
boolean
(optional, default: false)
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.)
dataKeyReuse?
Type:
Duration
(optional, default: Duration.minutes(5))
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).
deadLetterQueue?
Type:
Dead
(optional, default: no dead-letter queue)
Send messages to this queue if they were unsuccessfully dequeued a number of times.
deduplicationScope?
Type:
Deduplication
(optional, default: DeduplicationScope.QUEUE)
For high throughput for FIFO queues, specifies whether message deduplication occurs at the message group or queue level.
(Only applies to FIFO queues.)
deliveryDelay?
Type:
Duration
(optional, default: 0)
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.
encryption?
Type:
Queue
(optional, default: Unencrypted)
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.
encryptionMasterKey?
Type:
IKey
(optional, default: If encryption is set to KMS and not specified, a key will be created.)
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.
If the 'encryptionMasterKey' property is set, 'encryption' type will be implicitly set to "KMS".
fifo?
Type:
boolean
(optional, default: false, unless queueName ends in '.fifo' or 'contentBasedDeduplication' is true.)
Whether this a first-in-first-out (FIFO) queue.
fifoThroughputLimit?
Type:
Fifo
(optional, default: FifoThroughputLimit.PER_QUEUE)
For high throughput for FIFO queues, specifies whether the FIFO queue throughput quota applies to the entire queue or per message group.
(Only applies to FIFO queues.)
maxMessageSizeBytes?
Type:
number
(optional, default: 256KiB)
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).
queueName?
Type:
string
(optional, default: CloudFormation-generated name)
A name for the queue.
If specified and this is a FIFO queue, must end in the string '.fifo'.
receiveMessageWaitTime?
Type:
Duration
(optional, default: 0)
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.
removalPolicy?
Type:
Removal
(optional, default: RemovalPolicy.DESTROY)
Policy to apply when the queue is removed from the stack.
Even though queues are technically stateful, their contents are transient and it
is common to add and remove Queues while rearchitecting your application. The
default is therefore DESTROY
. Change it to RETAIN
if the messages are so
valuable that accidentally losing them would be unacceptable.
retentionPeriod?
Type:
Duration
(optional, default: Duration.days(4))
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).
visibilityTimeout?
Type:
Duration
(optional, default: Duration.seconds(30))
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.
Properties
Name | Type | Description |
---|---|---|
auto | boolean | Controls automatic creation of policy objects. |
env | Resource | The environment this resource belongs to. |
fifo | boolean | Whether this queue is an Amazon SQS FIFO queue. |
node | Construct | The construct tree node associated with this construct. |
queue | string | The ARN of this queue. |
queue | string | The name of this queue. |
queue | string | The URL of this queue. |
stack | Stack | The stack in which this resource is defined. |
dead | Dead | If this queue is configured with a dead-letter queue, this is the dead-letter queue settings. |
encryption | IKey | If this queue is encrypted, this is the KMS key. |
autoCreatePolicy
Type:
boolean
Controls automatic creation of policy objects.
Set by subclasses.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
fifo
Type:
boolean
Whether this queue is an Amazon SQS FIFO queue.
If false, this is a standard queue.
node
Type:
Construct
The construct tree node associated with this construct.
queueArn
Type:
string
The ARN of this queue.
queueName
Type:
string
The name of this queue.
queueUrl
Type:
string
The URL of this queue.
stack
Type:
Stack
The stack in which this resource is defined.
deadLetterQueue?
Type:
Dead
(optional)
If this queue is configured with a dead-letter queue, this is the dead-letter queue settings.
encryptionMasterKey?
Type:
IKey
(optional)
If this queue is encrypted, this is the KMS key.
Methods
Name | Description |
---|---|
add | Adds a statement to the IAM resource policy associated with this queue. |
apply | Apply the given removal policy to this resource. |
grant(grantee, ...actions) | Grant the actions defined in queueActions to the identity Principal given on this SQS queue resource. |
grant | Grant permissions to consume messages from a queue. |
grant | Grant an IAM principal permissions to purge all messages from the queue. |
grant | Grant access to send messages to a queue to the given identity. |
metric(metricName, props?) | Return the given named metric for this Queue. |
metric | The approximate age of the oldest non-deleted message in the queue. |
metric | The number of messages in the queue that are delayed and not available for reading immediately. |
metric | The number of messages that are in flight. |
metric | The number of messages available for retrieval from the queue. |
metric | The number of ReceiveMessage API calls that did not return a message. |
metric | The number of messages deleted from the queue. |
metric | The number of messages returned by calls to the ReceiveMessage action. |
metric | The number of messages added to a queue. |
metric | The size of messages added to a queue. |
to | Returns a string representation of this construct. |
static from | Import an existing SQS queue provided an ARN. |
static from | Import an existing queue. |
addToResourcePolicy(statement)
public addToResourcePolicy(statement: PolicyStatement): AddToResourcePolicyResult
Parameters
- statement
Policy
Statement
Returns
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 imported (Queue.import
), then this is a no-op.
applyRemovalPolicy(policy)
public applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
grant(grantee, ...actions)
public grant(grantee: IGrantable, ...actions: string[]): Grant
Parameters
- grantee
IGrantable
— Principal to grant right to. - actions
string
— The actions to grant.
Returns
Grant the actions defined in queueActions to the identity Principal given on this SQS queue resource.
grantConsumeMessages(grantee)
public grantConsumeMessages(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— Principal to grant consume rights to.
Returns
Grant permissions to consume messages from a queue.
This will grant the following permissions:
- sqs:ChangeMessageVisibility
- sqs:DeleteMessage
- sqs:ReceiveMessage
- sqs:GetQueueAttributes
- sqs:GetQueueUrl
grantPurge(grantee)
public grantPurge(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— Principal to grant send rights to.
Returns
Grant an IAM principal permissions to purge all messages from the queue.
This will grant the following permissions:
- sqs:PurgeQueue
- sqs:GetQueueAttributes
- sqs:GetQueueUrl
grantSendMessages(grantee)
public grantSendMessages(grantee: IGrantable): Grant
Parameters
- grantee
IGrantable
— Principal to grant send rights to.
Returns
Grant access to send messages to a queue to the given identity.
This will grant the following permissions:
- sqs:SendMessage
- sqs:GetQueueAttributes
- sqs:GetQueueUrl
metric(metricName, props?)
public metric(metricName: string, props?: MetricOptions): Metric
Parameters
- metricName
string
- props
Metric
Options
Returns
Return the given named metric for this Queue.
metricApproximateAgeOfOldestMessage(props?)
public metricApproximateAgeOfOldestMessage(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The approximate age of the oldest non-deleted message in the queue.
Maximum over 5 minutes
metricApproximateNumberOfMessagesDelayed(props?)
public metricApproximateNumberOfMessagesDelayed(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages in the queue that are delayed and not available for reading immediately.
Maximum over 5 minutes
metricApproximateNumberOfMessagesNotVisible(props?)
public metricApproximateNumberOfMessagesNotVisible(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages that are in flight.
Maximum over 5 minutes
metricApproximateNumberOfMessagesVisible(props?)
public metricApproximateNumberOfMessagesVisible(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages available for retrieval from the queue.
Maximum over 5 minutes
metricNumberOfEmptyReceives(props?)
public metricNumberOfEmptyReceives(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of ReceiveMessage API calls that did not return a message.
Sum over 5 minutes
metricNumberOfMessagesDeleted(props?)
public metricNumberOfMessagesDeleted(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages deleted from the queue.
Sum over 5 minutes
metricNumberOfMessagesReceived(props?)
public metricNumberOfMessagesReceived(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages returned by calls to the ReceiveMessage action.
Sum over 5 minutes
metricNumberOfMessagesSent(props?)
public metricNumberOfMessagesSent(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The number of messages added to a queue.
Sum over 5 minutes
metricSentMessageSize(props?)
public metricSentMessageSize(props?: MetricOptions): Metric
Parameters
- props
Metric
Options
Returns
The size of messages added to a queue.
Average over 5 minutes
toString()
public toString(): string
Returns
string
Returns a string representation of this construct.
static fromQueueArn(scope, id, queueArn)
public static fromQueueArn(scope: Construct, id: string, queueArn: string): IQueue
Parameters
- scope
Construct
— The parent creating construct. - id
string
— The construct's name. - queueArn
string
— queue ARN (i.e. arn:aws:sqs:us-east-2:444455556666:queue1).
Returns
Import an existing SQS queue provided an ARN.
static fromQueueAttributes(scope, id, attrs)
public static fromQueueAttributes(scope: Construct, id: string, attrs: QueueAttributes): IQueue
Parameters
- scope
Construct
- id
string
- attrs
Queue
Attributes
Returns
Import an existing queue.