Keith Yager
Fabled Bits Web Development


Fabled Bits Web Development

What is Amazon Simple Queue Service?

What is Amazon Simple Queue Service?

Keith Yager's photo
Keith Yager
·Aug 12, 2021·

4 min read

Amazon Simple Queue Service, or SQS for short, is essentially a middleman between your application and your logic that processes the information it receives.

You can think of SQS as a mailman. Someone writes a letter, the mailman picks it up (This would be SQS), and then that mailman delivers that letter to it's intended destination.

The only difference is that this particular mailman, is really freaking good at his job, and he can deliver your mail in a very efficient manner, to it's proper destination, and in the proper order. He can even pick up mail in the process of delivering some other mail, and then handle the new mail once he's done delivering his other mail.

However, sometimes he moves so fast that he can deliver the same piece of mail more than once, so it's important that the recipient has the proper devices (or code) in place to prevent opening a piece of mail more than once.

Amazon SQS is designed to be a highly available service to deliver messages in a reliable manner, in newer versions of SQS, you can also guarantee first in, first out, or FIFO delivery.

If the ordering of your messages is important, you can place sequencing information inside your messages so that they can be ordered properly once the messages are received.

Messages must also contain two properties, the message ID, and the body.

Delays and Visibility

Messages sent through SQS can be delayed by a number of seconds of your choosing, during this period, the message is invisible to the recipient.

Delays can be anywhere from 0 to 900 seconds, or up to 15 minutes. Delay's can be added or removed from existing queues simply by changing the delay value, a value of 0 disables delays.

Another similar feature is Visibility Timeouts, which also makes the message unavailable to the recipient, but only after the message is retrieved. So basically you have the letter from the mailman, but you can't open it yet. The default visibility timeout is 30 seconds, and can be changed to up to 12 hours maximum for a visibility timeout.

While the message is in this timeout, it is considered "in flight", and you can have a maximum of 120,000 messages in flight at any given time.

The Data

Amazon SQS uses a globally unique ID which is returned by SQS when the message is delivered, and can be used to check whether a particular message has been delivered or not.

Messages are also sent with a receipt handle in the response, which must be provided when deleting a message from the queue. This means that in order to delete a message, you have to receive it first. So you can't tell the mailman to stop delivering something while he's in the process of delivering it or other mail.

Message Attributes

Amazon SQS allows you to attach metadata to your messages, to help you tell the recipient more about the message and how to handle it. Using additional metadata is optional.

You can attach up to 10 pieces of metadata to each message.

Long Polling

Depending on how your application works, you may want to use long polling so that you aren't constantly hammering the mailman to check if he has new mail for you, otherwise you will drive up his prices a lot more for the extra work he has to do, or in AWS's case, use up all your precious CPU cycles.

Using long polling allows your request to check for new messages and wait a certain number of seconds before it comes back with an answer. The wait time can be anywhere from 1 to 20 seconds maximum.

Message Retention

Retention for messages can be set for up to 14 days, and the default retention period is four days.

Dead Letter Queues

Amazon SQS also supports a feature called dead letter queues, in simple terms, think of it as a "Return to sender" pile for the mail you receive that you either couldn't understand or was missing the information you required to process it.

This places the undeliverable messages into it's own separate queue, that you can then use to process and analyze the messages and perform additional tasks on them as needed, such as trying to send the message again, or letting someone know that it didn't get delivered.

Access and Security

Amazon SQS Access Control allows you to grant access to your SQS queue to another AWS account, it functions similar to IAM, but is it's own separate entity.

A sample access policy looks like this:

  "Version": "2008-10-17",
  "Id": "__default_policy_ID",
  "Statement": [
      "Sid": "__owner_statement",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::1234567890:root"
      "Action": "SQS:*",
      "Resource": "arn:aws:sqs:us-east-1:1234567890:my-queue"

These are the basics of Amazon SQS that you will need to understand for your exam. It is recommended to play around with a test SQS Queue that you create to get more familiar with the service.

Share this