If you've got a moment, please tell us what we did right so we can do more of it. Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better. Sets the value of one or more queue attributes. When you change a queue's attributes, the change can take up to 60 seconds for most of the attributes to propagate throughout the Amazon SQS system.
Changes made to the MessageRetentionPeriod attribute can take up to 15 minutes. In the future, new attributes might be added. If you write code that calls this action, we recommend that you structure your code so that it can handle new attributes gracefully.
Amazon SQS message attributes
Cross-account permissions don't apply to this action. For information about the parameters that are common to all actions, see Common Parameters. The following lists the names, descriptions, and values of the special request parameters that the SetQueueAttributes action uses:. DelaySeconds — The length of time, in seconds, for which the delivery of all messages in the queue is delayed.
Valid values: An integer from 0 to 15 minutes. Default: 0. Default:KiB. Valid values: An integer representing seconds, from 60 1 minute to 1, 14 days. Default:4 days. Policy — The queue's policy.
A valid AWS policy. Valid values: An integer from 0 to 20 seconds. RedrivePolicy — The string that includes the parameters for the dead-letter queue functionality of the source queue as a JSON object. Similarly, the dead-letter queue of a standard queue must also be a standard queue. VisibilityTimeout — The visibility timeout for the queue, in seconds.
Valid values: An integer from 0 to 43, 12 hours. Default: The following attributes apply only to server-side-encryption :. For more information, see Key Terms. An integer representing seconds, between 60 seconds 1 minute and 86, seconds 24 hours.
Default: 5 minutes. A shorter time period provides better security but results in more calls to KMS which might incur charges after Free Tier. The following attribute applies only to FIFO first-in-first-out queues :.
ContentBasedDeduplication — Enables content-based deduplication. If you don't provide a MessageDeduplicationId and the queue doesn't have ContentBasedDeduplication set, the action fails with an error.
When ContentBasedDeduplication is in effect, messages with identical content sent within the deduplication interval are treated as duplicates and only one copy of the message is delivered.
If you send one message with ContentBasedDeduplication enabled and then another message with a MessageDeduplicationId that is the same as the one generated for the first MessageDeduplicationIdthe two messages are treated as duplicates and only one copy of the message is delivered. For information about the errors that are common to all actions, see Common Errors.
The following example query request sets a policy that gives all users ReceiveMessage permission for a queue named MyQueue. The following example query request sets the visibility timeout to 35 seconds for a queue named MyQueue. A message is considered to be stored after it is sent to a queue by a producer, but not yet received from the queue by a consumer that is, between states 1 and 2.If you've got a moment, please tell us what we did right so we can do more of it.
Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better. Amazon SQS lets you include structured metadata such as timestamps, geospatial data, signatures, and identifiers with messages using message attributes.
Each message can have up to 10 attributes.
Amazon SQS FAQs
Message attributes are optional and separate from the message body however, they are sent alongside it. Your consumer can use message attributes to handle a message in a particular way without having to process the message body first.
Don't confuse message attributes with message system attributes : Whereas you can use message attributes to attach custom metadata to Amazon SQS messages for your applications, you can use message system attributes to store metadata for other AWS services, such as AWS X-Ray. All components of a message attribute are included in the KB message size restriction. The NameTypeValueand the message body must not be empty or null.
The following restrictions apply:. Can't start with AWS. Type — The message attribute data type. Supported types include StringNumberand Binary. You can also add custom information for any data type. In addition, the following restrictions apply:. Value — The message attribute value. For String data types, the attribute values has the same restrictions as the message body.
Message attribute data types instruct Amazon SQS how to handle the corresponding message attribute values. Amazon SQS supports the logical data types StringNumberand Binary with optional custom data type labels with the format. Number — Number attributes can store positive or negative numerical values. Binary — Binary attributes can store any binary data such as compressed data, encrypted data, or images.
Custom — To create a custom data type, append a custom-type label to any data type. For example:. The custom-type label has the same restrictions as the message body. Encode the individual parts of each attribute NameTypeand Value into a buffer. The following diagram shows the encoding of the MD5 message digest for a single message attribute:.If you've got a moment, please tell us what we did right so we can do more of it.
Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better. Amazon SNS supports delivery of message attributes, which let you provide structured metadata items such as timestamps, geospatial data, signatures, and identifiers about the message.
Each message can have up to 10 attributes. Message attributes are optional and separate from—but are sent together with—the message body. The receiver can use this information to decide how to handle the message without having to process the message body first.
You can also use message attributes to help structure the push notification message for mobile endpoints. In this scenario, the message attributes are used only to help structure the push notification message.
The attributes are not delivered to the endpoint as they are when sending messages with message attributes to Amazon SQS endpoints. You can also use message attributes to make your messages filterable using subscription filter policies. You can apply filter policies to topic subscriptions. When a filter policy is applied, a subscription receives only those messages that have attributes that the policy accepts.
For more information, see Message Filtering. The name must not start or end with a period, and it should not have successive periods. The name is case-sensitive and must be unique among all attribute names for the message. The name can be up to characters long. The name cannot start with "AWS.
Type — The supported message attribute data types are StringString. ArrayNumberand Binary. The data type has the same restrictions on the content as the message body. The data type is case-sensitive, and it can be up to bytes long. For more information, see the Message attribute data types and validation section.
Value — The user-specified message attribute value. For string data types, the value attribute has the same restrictions on the content as the message body. Name, type, and value must not be empty or null. In addition, the message body should not be empty or null. All parts of the message attribute, including name, type, and value, are included in the message size restriction, which is KB. Message attribute data types identify how the message attribute values are handled by Amazon SNS.
For example, if the type is a number, Amazon SNS validates that it's a number. Array — An array, formatted as a string, that can contain multiple values.
The values can be strings, numbers, or the keywords truefalseand null. Number — Numbers are positive or negative integers or floating-point numbers. Numbers have sufficient range and precision to encompass most of the possible values that integers, floats, and doubles typically support. A number can have a value from 9 to 10 9with 5 digits of accuracy after the decimal point. Leading and trailing zeroes are trimmed. Binary — Binary type attributes can store any binary data; for example, compressed data, encrypted data, or images.The message filter feature enables endpoints subscribed to an SNS topic to receive only the subset of topic messages it is interested in.
In our example, users visit a website to place insurance quote requests. These quote requests can be for car insurance, boat insurance, or life insurance. When an insurance quote request is placed, the request is forwarded to a series of backend systems.
To get the event notifications to the right backend system, you could create a separate topic for each type of quote request, then add message routing logic to your publisher. However, this option can result in overly complicated publishers, topic proliferation, and additional overhead in provisioning and managing your SNS topics. SNS message filtering is much simpler!
Your first step will be to create an Amazon SNS topic to publish messages whenever quote requests are placed on an insurance website. These leads can be related to car insurance, boat insurance, or life insurance. When you click herethe AWS Management Console will open in a new browser window, so you can keep this step-by-step guide open. When the screen loads, enter your user name and password to get started. Then type notification in the search bar and select Simple Notification Service to open the service console.
If you don't see this page, skip to the next step. Each insurance sales system polls quote requests from its corresponding SQS message queue that is subscribed to the SNS topic.
The first queue will handle both car and boat insurance quote requests; the second queue will handle life insurance ones; and the third queue will catch all. The third queue will catch all quote requests, regardless of the insurance type, in order to feed an analytics system.
These preferences will be set as filter policies on the SNS subscriptions. In this step, you will create the three queues and subscribe each of them to the SNS topic. Click here to open the Amazon SQS console in a new browser window. Otherwise, proceed to the next step. Now that you have created your three Amazon SQS queues, you need to subscribe them to the Amazon SNS topic that broadcasts new insurance quote requests. The Subscribe to a Topic dialog box is displayed. From the Choose a Topic drop-down list, select your Insurance-Quote-Requests topic, which you want to subscribe your three queues to.
Because you created the SNS topic from the same account, it shows up in the list. A filter policy is simple JSON document, set as an attribute of the SNS subscription, which defines the type of notification the subscriber is interested in. Subscriptions without filter policies will receive all messages published to SNS topic, so you don't need to set a filtering policy for the All-Quotes queue for this scenario.
This will take you to the Edit subscription page. Click on the arrow to edit subscription filter policy. A confirmation dialog appears that confirms the subscription filter policy was successfully created. Now you will repeat the process add the filter policy to the second queue.If you've got a moment, please tell us what we did right so we can do more of it.
Thanks for letting us know this page needs work. We're sorry we let you down. If you've got a moment, please tell us how we can make the documentation better. For information about the parameters that are common to all actions, see Common Parameters. In the future, new attributes might be added. If you write code that calls this action, we recommend that you structure your code so that it can handle new attributes gracefully.
All — Returns all values. ApproximateNumberOfMessages — Returns the approximate number of messages available for retrieval from the queue.
ApproximateNumberOfMessagesDelayed — Returns the approximate number of messages in the queue that are delayed and not available for reading immediately. This can happen when the queue is configured as a delay queue or when a message has been sent with a delay parameter. Messages are considered to be in flight if they have been sent to a client but have not yet been deleted or have not yet reached the end of their visibility window. CreatedTimestamp — Returns the time when the queue was created in seconds epoch time.
DelaySeconds — Returns the default delay on the queue in seconds. LastModifiedTimestamp — Returns the time when the queue was last changed in seconds epoch time. Policy — Returns the policy of the queue. ReceiveMessageWaitTimeSeconds — Returns the length of time, in seconds, for which the ReceiveMessage action waits for a message to arrive. RedrivePolicy — The string that includes the parameters for the dead-letter queue functionality of the source queue as a JSON object.
VisibilityTimeout — Returns the visibility timeout for the queue. The following attributes apply only to server-side-encryption :. For more information, see Key Terms. The following attributes apply only to FIFO first-in-first-out queues :. ContentBasedDeduplication — Returns whether content-based deduplication is enabled for the queue. For information about the errors that are common to all actions, see Common Errors.
The dark mode beta is finally here. Change your preferences any time.Triggering AWS Lambda with SQS message using Serverless Framework
Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.
I have a SQS Queue from which messages are read by multiple hosts. I want to run some job business logic after all the messages in the queue have been processed. I want to stop my hosts polling for messages in the queue when there are no messages left and then run the required job. You could simply note empty receives from the API response while you're polling.
Concerning CloudWatch, there is another metric that would be a better fit for this. From the documentation :. I like doing consecutive periods because it makes it more evident that the queue was not only empty, but has stayed empty. You could trigger your post business logic on the cloud watch metric related to queue depth.
When the depth is 0 then you can send a SNS notification or start a lambda function. Also this cloud watch metric is better then others since this is actual message count reported by sqs service.
Learn more. Asked 3 years, 11 months ago. Active 3 years, 11 months ago. Viewed 11k times. How can I check that the queue is empty?
Any ideas? Active Oldest Votes. If you set up an alarm based on this metric, this means your minimum period should be 5 minutes. Sum is the most sensible statistic for your use case. Anthony Neace Anthony Neace Think so. ApproximateNumberOfMessagesNotVisible probably isn't extremely useful for this; there could be messages in-flight at the same instance CloudWatch samples and give you a false positive for queue depth. For the cloudwatch metrics, make sure you're sampling over several periods to verify that the queue is actually empty, and that there wasn't just a fluke or CloudWatch service error.
Rohit Rohit 2 2 silver badges 8 8 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.Amazon SQS provides several advantages over building your own software for managing message queues or using commercial or open-source message queuing systems that require significant up-front time for development and configuration. These alternatives require ongoing hardware maintenance and system administration resources.
The complexity of configuring and managing these systems is compounded by the need for redundant storage of messages that ensures messages are not lost if hardware fails.
In contrast, Amazon SQS requires no administrative overhead and little configuration. Amazon SQS works on a massive scale, processing billions of messages per day. You can scale the amount of traffic you send to Amazon SQS up or down without any configuration.
Amazon SQS also provides extremely high message durability, giving you and your stakeholders added confidence.
Amazon SQS is a message queue service used by distributed applications to exchange messages through a polling model, and can be used to decouple sending and receiving components. If you're using messaging with existing applications, and want to move your messaging to the cloud quickly and easily, we recommend you consider Amazon MQ. It supports industry-standard APIs and protocols so you can switch from any standards-based message broker to Amazon MQ without rewriting the messaging code in your applications.
FIFO first-in-first-out queues preserve the exact order in which messages are sent and received. If you use a FIFO queue, you don't have to place sequencing information in your messages. Standard queues provide a loose-FIFO capability that attempts to preserve the order of messages.
However, because standard queues are designed to be massively scalable using a highly distributed architecture, receiving messages in the exact order they are sent is not guaranteed. Standard queues provide at-least-once delivery, which means that each message is delivered at least once.
FIFO queues provide exactly-once processingwhich means that each message is delivered once and remains available until a consumer processes it and deletes it. Duplicates are not introduced into the queue. Amazon SQS offers a reliable, highly-scalable hosted queue for storing messages as they travel between applications or microservices.
It moves data between distributed application components and helps you decouple these components. Amazon SQS provides common middleware constructs such as dead-letter queues and poison-pill management.
Amazon Kinesis Streams allows real-time processing of streaming big data and the ability to read and replay records to multiple Amazon Kinesis Applications. The Amazon Kinesis Client Library KCL delivers all records for a given partition key to the same record processor, making it easier to build multiple applications that read from the same Amazon Kinesis stream for example, to perform counting, aggregation, and filtering. For more information, see the Amazon Kinesis Documentation.
Developers at Amazon use Amazon SQS for a variety of applications that process large numbers of messages every day. Key business processes in both Amazon. Many small-scale applications are able to operate entirely within the limits of the Free Tier. However, data transfer charges might still apply.
Yes, for any requests beyond the free tier.
All Amazon SQS requests are chargeable, and they are billed at the same rate. By grouping messages into batches, you can reduce your Amazon SQS costs. There are no initial fees to begin using Amazon SQS.