3 Things: Developing Amazon SQS Based Solutions


Amazon Simple Queue Service or Amazon SQS is a distributed message queuing service that enables developers to build loosely coupled solutions. Often valued for its ease of use, Amazon SQS queues can be spun up in a matter of seconds from the AWS console, SDK or the CLI. Still, there are subtleties that developers should be aware of when developing solutions with Amazon SQS.

Photo by Shumilov Ludmila on Unsplash


Messages stored in an Amazon SQS queue is data at rest. And, we can protect that data by encrypting it with KMS keys, just like we would if we were going to protect data in an Amazon S3 bucket or an Amazon SNS topic. With Amazon SQS Server-side encryption, messages are encrypted when they are received by SQS and are decrypted when delivered to a message consumer that is authorized for the SQS message queue and the KMS key.

Here is an example of a command for setting an Amazon SQS queue to use KMS encryption using the AWS CLI.

$ aws sqs set-queue-attributes \
––queue-url https://(MyNewQueueURL) \
––attributes ‘{“KmsMasterKeyId”: “(MyKeyId)”}’

Temporal Messages

By default, messages that are stored in Amazon SQS are designed for “At-Least-Once Delivery”. That is, an Amazon SQS message will be delivered at least once, but can be delivered more than once and there is no guarantee that your messages will stay ordered. However, if you need messages delivered in order and only once, you may opt for Amazon SQS FIFO queues. Amazon SQS FIFO queues are designed for, Exactly-Once Processing, where messages are only delivered once and are delivered in the order of, First-In-First-Out.

Below is an example of sending a message to an Amazon SQS FIFO queue using the AWS .NET. SDK. Note the use of the “MessageGroupId” property. This is a requirement for Amazon SQS FIFO queues.

SendMessageRequest sendMessageRequest = new SendMessageRequest(queueUrl, message);
sendMessageRequest.MessageGroupId = "message-group-1";
var sqsClient = new AmazonSQSClient();
await sqsClient.SendMessageAsync(sendMessageRequest);
view raw Program.cs hosted with ❤ by GitHub

Message Retention

Messages in Amazon SQS cannot be stored forever. In fact, messages in Amazon SQS can be stored for a maximum of 14 days, which for many workloads is plenty of time and for as little as 1 minute. By default, the Amazon SQS message retention period is a generous 4 days.

The following is an example of a command for setting an Amazon SQS queue to have a retention period of 1 minute using the AWS CLI.

$ aws sqs set-queue-attributes \
––queue-url https://(MyNewQueueURL) \
––attributes ‘{“MessageRetentionPeriod”: “60”}’

Want to know more about the tech in this article?  Checkout these resources:

AWS CLI, Configuring the AWS CLI, AWS .NET SDK, .NET

%d bloggers like this: