AWS::SQS::Queue
The AWS::SQS::Queue resource creates an Amazon Simple Queue Service (Amazon SQS) queue.
For more information about creating FIFO (first-in-first-out) queues, see the tutorial Create a queue using AWS CloudFormation in the Amazon Simple Queue Service Developer Guide.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::SQS::Queue", "Properties" : { "ContentBasedDeduplication" :Boolean, "DelaySeconds":Integer, "FifoQueue" :Boolean, "KmsMasterKeyId":String, "KmsDataKeyReusePeriodSeconds":Integer, "MaximumMessageSize":Integer, "MessageRetentionPeriod":Integer, "QueueName":String, "ReceiveMessageWaitTimeSeconds":Integer, "RedrivePolicy":RedrivePolicy, "Tags" : [Resource Tag, ...], "VisibilityTimeout":Integer} }
YAML
Type: AWS::SQS::Queue Properties: ContentBasedDeduplication:BooleanDelaySeconds:IntegerFifoQueue:BooleanKmsMasterKeyId:StringKmsDataKeyReusePeriodSeconds:IntegerMaximumMessageSize:IntegerMessageRetentionPeriod:IntegerQueueName:StringReceiveMessageWaitTimeSeconds:IntegerRedrivePolicy:RedrivePolicyTags:Resource TagVisibilityTimeout:Integer
Properties
ContentBasedDeduplication-
For first-in-first-out (FIFO) queues, specifies whether to enable content-based deduplication. During the deduplication interval, Amazon SQS treats messages that are sent with identical content as duplicates and delivers only one copy of the message. For more information, see the
ContentBasedDeduplicationattribute for the CreateQueue action in the Amazon Simple Queue Service API Reference.Required: No
Type: Boolean
Update requires: No interruption
DelaySeconds-
The time in seconds that the delivery of all messages in the queue is delayed. You can specify an integer value of
0to900(15 minutes). The default value is0.Required: No
Type: Integer
Update requires: No interruption
FifoQueue-
If set to
true, creates a FIFO queue. If you don't specify this property, Amazon SQS creates a standard queue. For more information, see FIFO (First-In-First-Out) Queues in the Amazon Simple Queue Service Developer Guide.Required: No
Type: Boolean
Update requires: Replacement
KmsMasterKeyId-
The ID of an AWS managed customer master key (CMK) for Amazon SQS or a custom CMK. To use the AWS managed CMK for Amazon SQS, specify the alias
alias/aws/sqs. For more information, see CreateQueue in the Amazon Simple Queue Service API Reference, Protecting Data Using Server-Side Encryption (SSE) and AWS KMS in the Amazon Simple Queue Service Developer Guide, or Customer Master Keys in the AWS Key Management Service Best Practices whitepaper.Required: No
Type: String
Update requires: No interruption
KmsDataKeyReusePeriodSeconds-
The length of time in seconds that Amazon SQS can reuse a data key to encrypt or decrypt messages before calling AWS KMS again. The value must be an integer between 60 (1 minute) and 86,400 (24 hours). The default is 300 (5 minutes).
Note
A shorter time period provides better security, but results in more calls to AWS KMS, which might incur charges after Free Tier. For more information, see How Does the Data Key Reuse Period Work? in the Amazon Simple Queue Service Developer Guide.
Required: No
Type: Integer
Update requires: No interruption
MaximumMessageSize-
The limit of how many bytes that a message can contain before Amazon SQS rejects it. You can specify an integer value from
1024bytes (1 KiB) to262144bytes (256 KiB). The default value is262144(256 KiB).Required: No
Type: Integer
Update requires: No interruption
MessageRetentionPeriod-
The number of seconds that Amazon SQS retains a message. You can specify an integer value from
60seconds (1 minute) to1209600seconds (14 days). The default value is345600seconds (4 days).Required: No
Type: Integer
Update requires: No interruption
QueueName-
A name for the queue. To create a FIFO queue, the name of your FIFO queue must end with the
.fifosuffix. For more information, see FIFO (First-In-First-Out) Queues in the Amazon Simple Queue Service Developer Guide.If you don't specify a name, AWS CloudFormation generates a unique physical ID and uses that ID for the queue name. For more information, see Name Type.
Important
If you specify a name, you cannot perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.
Required: No
Type: String
Update requires: Replacement
ReceiveMessageWaitTimeSeconds-
Specifies the duration, in seconds, that the
ReceiveMessageaction call waits until a message is in the queue in order to include it in the response, as opposed to returning an empty response if a message isn't yet available. You can specify an integer from1to20. The short polling is used as the default or when you specify0for this property. For more information, see Amazon SQS Long Poll.Required: No
Type: Integer
Update requires: No interruption
RedrivePolicy-
Specifies an existing dead letter queue to receive messages after the source queue (this queue) fails to process a message a specified number of times.
Required: No
Type: Amazon SQS RedrivePolicy
Update requires: No interruption
Tags-
The tags that you want to attach to this queue.
Required: No
Type: A list of resource tags
Update requires: No interruption
VisibilityTimeout-
The length of time during which a message will be unavailable after a message is delivered from the queue. This blocks other components from receiving the same message and gives the initial component time to process and delete the message from the queue.
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.
For more information about Amazon SQS queue visibility timeouts, see Visibility Timeout in the Amazon Simple Queue Service Developer Guide.
Required: No
Type: Integer
Update requires: No interruption
Return Values
Ref
The AWS::SQS::Queue type returns the queue URL. For example:
https://sqs.us-east-2.amazonaws.com/123456789012/aa4-MyQueue-Z5NOSZO2PZE9.
For more information about using the Ref function, see Ref.
Fn::GetAtt
Fn::GetAtt returns a value for a specified attribute of this type.
The following are the available attributes and sample return values.
Arn-
Returns the Amazon Resource Name (ARN) of the queue. For example:
arn:aws:sqs:us-east-2:123456789012:mystack-myqueue-15PG5C2FC1CW8. QueueName-
Returns the queue name. For example:
mystack-myqueue-1VF9BKQH5BJVI
Examples
SQS Queue with Cloudwatch Alarms
JSON
{ "AWSTemplateFormatVersion" : "2010-09-09", "Description" : "AWS CloudFormation Sample Template SQS_With_CloudWatch_Alarms: Sample template showing how to create an SQS queue with Amazon CloudWatch alarms on queue depth. **WARNING** This template creates an Amazon SQS queue and one or more Amazon CloudWatch alarms. You will be billed for the AWS resources used if you create a stack from this template.", "Parameters" : { "AlarmEmail": { "Default": "[email protected]", "Description": "Email address to notify if operational problems arise", "Type": "String" } }, "Resources" : { "MyQueue" : { "Type" : "AWS::SQS::Queue", "Properties" : { "QueueName" : "SampleQueue" } }, "AlarmTopic": { "Type": "AWS::SNS::Topic", "Properties": { "Subscription": [{ "Endpoint": { "Ref": "AlarmEmail" }, "Protocol": "email" }] } }, "QueueDepthAlarm": { "Type": "AWS::CloudWatch::Alarm", "Properties": { "AlarmDescription": "Alarm if queue depth grows beyond 10 messages", "Namespace": "AWS/SQS", "MetricName": "ApproximateNumberOfMessagesVisible", "Dimensions": [{ "Name": "QueueName", "Value" : { "Fn::GetAtt" : ["MyQueue", "QueueName"] } }], "Statistic": "Sum", "Period": "300", "EvaluationPeriods": "1", "Threshold": "10", "ComparisonOperator": "GreaterThanThreshold", "AlarmActions": [{ "Ref": "AlarmTopic" }], "InsufficientDataActions": [{ "Ref": "AlarmTopic" }] } } }, "Outputs" : { "QueueURL" : { "Description" : "URL of newly created SQS Queue", "Value" : { "Ref" : "MyQueue" } }, "QueueARN" : { "Description" : "ARN of newly created SQS Queue", "Value" : { "Fn::GetAtt" : ["MyQueue", "Arn"]} }, "QueueName" : { "Description" : "Name newly created SQS Queue", "Value" : { "Fn::GetAtt" : ["MyQueue", "QueueName"]} } } }
YAML
AWSTemplateFormatVersion: "2010-09-09" Description: "AWS CloudFormation Sample Template SQS_With_CloudWatch_Alarms: Sample template showing how to create an SQS queue with Amazon CloudWatch alarms on queue depth. **WARNING** This template creates an Amazon SQS queue and one or more Amazon CloudWatch alarms. You will be billed for the AWS resources used if you create a stack from this template." Parameters: AlarmEmail: Default: "[email protected]" Description: "Email address to notify if operational problems arise" Type: "String" Resources: MyQueue: Type: AWS::SQS::Queue Properties: QueueName: "SampleQueue" AlarmTopic: Type: AWS::SNS::Topic Properties: Subscription: - Endpoint: Ref: "AlarmEmail" Protocol: "email" QueueDepthAlarm: Type: AWS::CloudWatch::Alarm Properties: AlarmDescription: "Alarm if queue depth grows beyond 10 messages" Namespace: "AWS/SQS" MetricName: "ApproximateNumberOfMessagesVisible" Dimensions: - Name: "QueueName" Value: Fn::GetAtt: - "MyQueue" - "QueueName" Statistic: "Sum" Period: "300" EvaluationPeriods: "1" Threshold: "10" ComparisonOperator: "GreaterThanThreshold" AlarmActions: - Ref: "AlarmTopic" InsufficientDataActions: - Ref: "AlarmTopic" Outputs: QueueURL: Description: "URL of newly created SQS Queue" Value: Ref: "MyQueue" QueueARN: Description: "ARN of newly created SQS Queue" Value: Fn::GetAtt: - "MyQueue" - "Arn" QueueName: Description: "Name newly created SQS Queue" Value: Fn::GetAtt: - "MyQueue" - "QueueName"
SQS Queue with a Dead Letter Queue
The following sample creates a source queue and a dead letter queue. Because the source queue specifies the dead letter queue in its redrive policy, the source queue is dependent on the creation of the dead letter queue.
JSON
{ "AWSTemplateFormatVersion" : "2010-09-09", "Resources" : { "MySourceQueue" : { "Type" : "AWS::SQS::Queue", "Properties" : { "RedrivePolicy": { "deadLetterTargetArn" : {"Fn::GetAtt" : [ "MyDeadLetterQueue" , "Arn" ]}, "maxReceiveCount" : 5 } } }, "MyDeadLetterQueue" : { "Type" : "AWS::SQS::Queue" } }, "Outputs" : { "SourceQueueURL" : { "Description" : "URL of the source queue", "Value" : { "Ref" : "MySourceQueue" } }, "SourceQueueARN" : { "Description" : "ARN of the source queue", "Value" : { "Fn::GetAtt" : ["MySourceQueue", "Arn"]} }, "DeadLetterQueueURL" : { "Description" : "URL of the dead letter queue", "Value" : { "Ref" : "MyDeadLetterQueue" } }, "DeadLetterQueueARN" : { "Description" : "ARN of the dead letter queue", "Value" : { "Fn::GetAtt" : ["MyDeadLetterQueue", "Arn"]} } } }
YAML
AWSTemplateFormatVersion: "2010-09-09" Resources: MySourceQueue: Type: AWS::SQS::Queue Properties: RedrivePolicy: deadLetterTargetArn: Fn::GetAtt: - "MyDeadLetterQueue" - "Arn" maxReceiveCount: 5 MyDeadLetterQueue: Type: AWS::SQS::Queue Outputs: SourceQueueURL: Description: "URL of the source queue" Value: Ref: "MySourceQueue" SourceQueueARN: Description: "ARN of the source queue" Value: Fn::GetAtt: - "MySourceQueue" - "Arn" DeadLetterQueueURL: Description: "URL of the dead letter queue" Value: Ref: "MyDeadLetterQueue" DeadLetterQueueARN: Description: "ARN of the dead letter queue" Value: Fn::GetAtt: - "MyDeadLetterQueue" - "Arn"
See Also
-
CreateQueue in the Amazon Simple Queue Service API Reference
-
What is Amazon Simple Queue Service? in the Amazon Simple Queue Service Developer Guide
