Amazon Simple Queue Service (Amazon SQS) offers a secure, durable, and available hosted queue that lets you integrate and decouple distributed software systems and components. Amazon SQS offers common constructs such as and . It provides a generic web services API that you can access using any programming language that the AWS SDK supports. This is known as decoupling / loose coupling and helps to enable elasticity for your application. Amazon SQS is pull-based, not push-based (like Amazon SNS). Benefits of using Amazon SQS
Security – who can send messages to and receive messages from an Amazon SQS queue. You can choose to transmit sensitive data by protecting the contents of messages in queues by using default Amazon SQS managed server-side encryption (SSE), or by using custom keys managed in AWS Key Management Service (AWS KMS). Durability – For the safety of your messages, Amazon SQS stores them on multiple servers. Standard queues support , and FIFO queues support and mode. Availability – Amazon SQS uses to provide highly-concurrent access to messages and high availability for producing and consuming messages. Scalability – Amazon SQS can process each independently, scaling transparently to handle any load increases or spikes without any provisioning instructions. Reliability – Amazon SQS locks your messages during processing, so that multiple producers can send and multiple consumers can receive messages at the same time. Customization – Your queues don't have to be exactly alike—for example, you can . You can store the contents of messages larger than 256 KB or Amazon DynamoDB, with Amazon SQS holding a pointer to the Amazon S3 object, or you can split a large message into smaller messages. Amazon SQS queue types
Amazon SQS supports two types of queues – standard queues and FIFO queues. Use the information from the following table to choose the right queue for your situation. To learn more about Amazon SQS queues, see and . Using dead-letter queues in Amazon SQS
Amazon SQS supports dead-letter queues, which source queues can target for messages that are not processed successfully. Dead-letter queues are useful for debugging your application because you can isolate unconsumed messages to determine why processing did not succeed. Once messages are in a dead-letter queue, you can:
Examine logs for exceptions that might have caused messages to be moved to a dead-letter queue. Analyze the contents of messages moved to the dead-letter queue to diagnose application issues. Determine whether you have given your consumer sufficient time to process messages. Move messages out of the dead-letter queue using . You must first create a new queue before configuring it as a dead-letter queue. For information about configuring a dead-letter queue using the Amazon SQS console, see . For help with dead-letter queues, such as how to configure an alarm for any messages moved to a dead-letter queue, see . Using policies for dead-letter queues
Use a redrive policy to specify the maxReceiveCount. The maxReceiveCount is the number of times a consumer can receive a message from a source queue before it is moved to a dead-letter queue. For example, if the maxReceiveCount is set to a low value such as 1, one failure to receive a message would cause the message to move to the dead-letter queue. To ensure that your system is resilient against errors, set the maxReceiveCount high enough to allow for sufficient retries.
The redrive allow policy specifies which source queues can access the dead-letter queue. You can choose whether to allow all source queues, allow specific source queues, or deny all source queues use of the dead-letter queue. The default allows all source queues to use the dead-letter queue. If you choose to allow specific queues using the byQueue option, you can specify up to 10 source queues using the source queue Amazon Resource Name (ARN). If you specify denyAll, the queue cannot be used as a dead-letter queue.
Amazon SQS short and long polling
Amazon SQS offers short and long polling options for receiving messages from a queue. Consider your application's requirements for responsiveness and cost efficiency when choosing between these two polling options:
Short polling (default) – The request queries a subset of servers (based on a weighted random distribution) to find available messages and sends an immediate response, even if no messages are found. Long polling – queries all servers for messages, sending a response once at least one message is available, up to the specified maximum. An empty response is sent only if the polling wait time expires. This option can reduce the number of empty responses and potentially lower costs. When the wait time for the API action is greater than 0, long polling is in effect. The maximum long polling wait time is 20 seconds. Long polling helps reduce the cost of using Amazon SQS by eliminating the number of empty responses (when there are no messages available for a ReceiveMessage request) and false empty responses (when messages are available but aren't included in a response). Differences between long and short polling
Short polling occurs when the parameter of a request is set to 0 in one of two ways: The ReceiveMessage call sets WaitTimeSeconds to 0. The ReceiveMessage call doesn’t set WaitTimeSeconds, but the queue attribute is set to 0.
Using Amazon SQS and IAM policies
There are two ways to give your users permissions to your Amazon SQS resources: using the Amazon SQS policy system and using the IAM policy system. You can use one or the other, or both. For the most part, you can achieve the same result with either one.
For example, the following diagram shows an IAM policy and an Amazon SQS policy equivalent to it. The IAM policy grants the rights to the Amazon SQS ReceiveMessage and SendMessage actions for the queue called queue_xyz in your AWS Account, and the policy is attached to users named Bob and Susan (Bob and Susan have the permissions stated in the policy). This Amazon SQS policy also gives Bob and Susan rights to the ReceiveMessage and SendMessage actions for the same queue.
Visibility timeout
The visibility timeout is the amount of time a message is invisible in the queue after a reader picks up the message.
If a job is processed within the visibility timeout the message will be deleted. If a job is not processed within the visibility timeout the message will become visible again (could be delivered twice). The maximum visibility timeout for an Amazon SQS message is 12 hours.