What is AWS SQS (Simple Queue Service)?
Tags: aws, tutorial, sqs, cloud
Published: 2023-01-23 16:07:20

AWS SQS is a messaging queue service provided by AWS. Sometimes you can have many applications deployed on AWS, and with SQS you can easily communicate with your services.

These communications may be synchronous(where your applications directly communicate with each other) or asynchronous(where you can have a middleware that connects these applications)

Before we dive into the features of SQS, we need to understand some concepts.

- Message: It is a blob that can contain any data
- Queue: You can imagine a queue as a temporary house that allows you to store messages till the messages are processed and deleted.
- Polling: This is a mechanism that can be used to receive messages from queues.
- Producer: A producer sends messages to the queue. You can have one or more producers sending messages to the queue
- Consumer: A consumer receives(polls) messages from the queue. You can have multiple consumers.

###Features of AWS SQS
- **Visibility Timeout**
When a message is polled and processed by the consumer, it remains in the queue and does not get deleted automatically. While the message is being processed, SQS will set a time during which the message because invisible to other consumers, to prevent them from receiving and processing the message. By default, the visibility timeout is 30 seconds, with a minimum time of 0 seconds and a maximum time of 12 hours.

- **Dead-Letter Queues**
So what if a message is not processed within the visibility timeout? The message goes back into the message queue and is then retried to be processed until a maximum number is reached before it is then sent to the dead-letter queue. One useful thing about DLQs is that it allows you to debug your applications easily by isolating the messages that fail to be processed.
- **FIFO Queues**
FIFO means First In First Out which is the order in which messages are being sent and received by the consumer. The FIFO queue supports up to 300 messages per second. If you're using FIFO queues, dead-letter queues can break the order.
- **Delay Queues**
With delay queues, messages can be delayed before they are delivered. Any message sent to this queue would be invisible to the consumers for the duration of the delay period. By default, the minimum delay period is 0 seconds and maximum time of 15 minutes. Unlike the visibility timeout where messages are hidden until they are consumed, with delay queues the messages are hidden as soon as it is added to the queue.

###SQS Hands-On

How to create an Amazon SQS queue from AWS console
- on the console search for SQS
- click on create queue
- for the type you can choose the standard or FIFO queue, by default the queue is set to standard
![standard or FIFO queue](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1xnte3d5zgleeli239h.png)
- enter a name for your queue
- under Configuration, you can leave it as the default or set new values
![set Configuration](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7loqtm6e8ep2ndir67dy.png)
- by default AWS SQS manages server-side encryption. You can disable it or choose an encryption key
- you can also choose who can access your queue. For the basic option,  define who can send messages to the queue and who can receive messages from the queue. For the advanced option, the JSON object can be modified directly and custom actions can be set.
- you can modify the redrive allow policy (optional)
- you can also enable dead-letter-queue (optional)
and lastly add tags(optional)
- Finally, your queue has been created!!!

![queue created](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d0lz0xa6b1ktxvi1nbqz.png)
You can:
- edit: modify queue
- delete the queue
- purge:  delete all the messages created
- send and receive message 

####How to send and receive messages
- click on the send and receive message
- enter your message in the message body

![enter your message](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nh0qfczdn938uwjdg8rn.png)
- click on send message

![send the message](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/th0im7pslus65ij2q5gf.png)
- scroll down to receive message
- click on poll for messages

![poll for messages](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ion9t8w6j5jbhshddafv.png)
- your created message should appear

![your created message should appear](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lwlpyoah30kjhng7xhit.png)
- click on the id to see more details about the message

![click on id](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gulx0xk02yna9p1i58yy.png)
- after processing and receiving the message, you can delete it manually

![delete messages manually](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kct40wzhs8u07q0g23tu.png)
 

###Conclusion: When can you use SQS?
- It can be used to decouple and scale services
- Multiple SQS queues can be used to process messages in parallel
- Together with AWS SNS(Simple Notification Service), SQS can be used for monitoring and creating alerts in your application