Free access is closing! 700+ free courses are waiting.
Ends in:
Start Now
Now that we understand what SQS is let's look at how to set it up. This section will guide you through the prerequisites and how to access the SQS console.
Before you start using AWS SQS, ensure you have:
To set up IAM permissions:

Setting up AWS SQS
sqs:CreateQueue, sqs:DeleteQueue, sqs:SendMessage, sqs:ReceiveMessage, sqs:DeleteMessage.
Setting up AWS SQS

Setting up AWS SQS
The final policy should look like this in JSON format:

Setting up AWS SQS
Let’s have a brief overview of our policy definition:
“Version”: “2012-10-17” is the current version of the IAM policy language.“Statement”, which defines a set of permissions.“Sid”: “VisualEditor0” means that this policy has been created via a visual editor.“Effect”: “Allow” means these actions are being permitted.“Action”: This list specifies the above SQS operations that are allowed:“Resource”: “*” means these actions are allowed on all SQS resources in the account.This policy gives full access to create, delete, send, and receive messages from any SQS queue in the account. It's pretty permissive, so we might want to restrict it to specific queue ARNs for better security in a production environment.
If you want to learn more about IAM configuration, The Complete Guide to AWS Identity and Access Management (IAM) tutorial teaches how to secure your AWS environment, manage access with users, groups, and roles, and implement best practices for robust security.
To deepen your knowledge of AWS configuration, the How to Setup and Configure AWS: A Comprehensive Tutorial would be helpful to discover essential settings, best practices for security, and how to leverage AWS Services for data analysis and machine learning.
Once the prerequisites are in place, the next step is to access the SQS console to start creating and managing queues. Here are the steps to access the console:

Accessing the Amazon SQS console
With access to the SQS console, we can start creating and managing queues. This section will walk through creating both standard and FIFO queues.
But wait, where does our IAM Policy come into play?
The IAM policy we created in the prerequisites section is crucial for queue creation and management. Here's how it factors in:
sqs:CreateQueue permission in our policy specifically allows queue creation. Without this, you would receive an "Access Denied" error when creating a queue.sqs:SendMessage, sqs:ReceiveMessage, sqs:DeleteMessage, sqs:DeleteQueue) allow you to perform various operations on the queue after creation.With that understanding, let’s continue creating our queues, starting with a standard queue.
Standard queues are the default queue type in SQS. Here's how to create one:

Creating a standard queue
A successful queue creation generates a message confirming its creation, as shown below, along with additional information about the queue.

Creating a standard queue
FIFO queues are used to guarantee the order of message processing, and below are the steps to create one:

Creating a FIFO queue
Similarly to the standard queue, the successful creation of the FIFO also provides the same details used for sending messages.

Creating a FIFO queue
When choosing between standard and FIFO queues in Amazon SQS, it’s important to understand their distinct features and capabilities.
The following table provides a comparative analysis to help you decide which queue type best suits your application’s needs:

Differences between standard and FIFO queues
Now that all our queues are set up, let’s start sending and receiving messages. This section covers how to do this through the AWS Management Console and the AWS Command Line Interface (CLI).
The process of sending messages is shown using the standard and FIFO queues.

Sending messages using the AWS management console
After sending the message, a pop-up confirms that it was sent. Clicking “View details” provides the details of our message, as shown below.

Sending messages using the AWS management console
Finally, in the “Receive messages” section, we can see that one message is available.

Sending messages using the AWS management console
The main steps to sending a message via the CLI follow the template below.
For the standard queue method, our URL is given in the corresponding screenshot above. For the CLI, let’s use a different message:
The first step to start using the CLI is to configure it so that it can interact with our AWS resources, and this requires the following credentials:
Once the configuration is complete, run the following command with the correct argument values:
aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/022499002265/SQSHandsOn --message-body "Message sent via AWS CLI"
Sending messages using the CLI
The JSON output from the command execution corresponds to the details of the newly sent message, and we can see that there are now two messages within the SQSHandsOn queue.

Sending messages using the CLI
The process for sending messages using FIFO slightly differs from the standard queuing approach.
To better illustrate this scenario, imagine you're running an e-commerce platform selling electronic devices.
Your system needs to handle various operations, such as processing orders, updating inventory, and managing payments. In this case, we can use an SQS FIFO queue to ensure these operations are processed in the correct order and without duplicates.
Using a FIFO queue for these operations ensures that:
When sending messages to an SQS FIFO queue, remember two key elements:
With that understanding, let’s proceed with the CLI approach.
We can run the following commands to send the first two messages in the FIFO queue.
aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/022499002265/SQSHandsOn.fifo --message-body "Process customer order: #A1001" --message-group-id "CustomerOrders" --message-deduplication-id "Order-A1001-20240817-1"The output for this first execution is given below.

Example 1 - Sending message results using the CLI with FIFO
aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/022499002265/SQSHandsOn.fifo --message-body "Update inventory: ProductX -5 units" --message-group-id "InventoryUpdates" --message-deduplication-id "Inventory-ProductX-20240817-1"The output is given below.

Example 2 - Sending message results using the CLI with FIFO
So far, two messages have been sent to the FIFO queue, and can be seen below.

Sending messages result using the CLI with FIFO queues - Number of messages
Similarly to the standard queue, we can send messages from the management console as follows:

Sending messages result using the management console with FIFO queues
Now, we can see that the total number of messages in the FIFO queue is three.

Sending messages result using the management console with FIFO queues - Total number of messages
Receiving and deleting messages is just as important as sending them. Here's how to do both.

Receiving messages using the AWS management console with standard queue
All the two messages in the standard queue can be seen above.
Below is the general command for receiving messages from a standard queue.
Using our standard queue, the complete command becomes:
The process for retrieving messages via the management console follows the same process as the standard approach.
To receive messages from a FIFO queue using the AWS CLI, you can use the aws sqs receive-message command. Here's the basic structure:
aws sqs receive-message --queue-url https://sqs.us-east-1.amazonaws.com/022499002265/SQSHandsOn.fifo --attribute-names All --message-attribute-names All --max-number-of-messages 3-attribute-names All: Retrieves all message attributes.-message-attribute-names All: Retrieves all custom message attributes.--max-number-of-messages 3: Specifies the maximum number of messages toThe execution of the above command gives all three messages within the FIFO queue.

Receiving messages result using the CLI with FIFO queues
Understanding the pricing model is crucial for using SQS cost-effectively. This section breaks down the pricing and offers tips for cost management.
In general, the AWS SQS pricing is based on the number of API requests made, data transfer, and optional features used.
The following tables provide an overview of the SQS requests pricing:
|
Standard Queues (per Million requests) |
FIFO Queues (per Million requests) | |
|
First 1 Million Requests/Month |
Free |
Free |
|
From 1 Million to 100 Billion Requests/Month |
$0.40 |
$0.5 |
|
From 100 Billion to 200 Billion Requests/Month |
$0.30 |
$0.40 |
|
Over 200 Billion Requests/Month |
0.24 |
$0.35 |
Pricing from the AWS SQS Page
To understand data transfer pricing, refer to the following table:
|
Data transfer IN |
Pricing |
|
All data transfer in |
$0.00 per GB |
|
Data transfer OUT |
Pricing |
|
First 10 TB/Month |
$0.09 per GB |
|
Next 40 TB / Month |
$0.085 per GB |
|
Next 100 TB / Month |
$0.07 per GB |
|
Greater than 150 TB / Month |
$0.05 per GB |
Pricing from the AWS SQS Page
Here are some quick tips to manage your SQS costs:
Effective monitoring is critical to maintaining a healthy SQS implementation. This section covers important metrics and how to set up alarms.
Here are some of the most important metrics to keep an eye on:

Key AWS SQS metrics
This metric represents the number of messages available for retrieval from the queue. It's an indicator of queue backlog and processing efficiency. A high number may indicate processing bottlenecks.
This metric shows how long the oldest non-deleted message has been in the queue. It helps identify potential issues with message processing, such as stuck messages or slow consumers. For FIFO queues, this metric is vital as it can indicate blocked message groups.
It tracks the number of messages added to the queue. It's useful for monitoring queue input rates and identifying unusual spikes in message production. Note that manually sent messages to dead-letter queues are included in this count.
This metric indicates how many messages have been returned to consumers from the queue. It helps track the queue's output rate and can be compared with NumberOfMessagesSent to gauge processing efficiency. Like NumberOfMessagesSent, it doesn't include messages automatically moved to dead-letter queues due to failed processing
A CloudWatch alarm creation is illustrated for the above four metrics. The process is the same for all those metrics. Hence, we are focusing on only one metric and only the Standard SQS (SQSHandsOn) for simplicity’s sake.
The main steps for setting up alarms for the ApproximateNumberOfMessagesVisible are below.
CloudWatch alarms can alert you to potential issues. Here's how to set them up from the management console:

Setting up CloudWatch alarms

Setting up CloudWatch alarms

Setting Up CloudWatch Alarms
The above configuration means that this alarm will trigger when the average number of visible messages in your SQSHandsOn queue exceeds 20 for at least one data point within 5 minutes. The graph shows the current message count (blue line) in relation to the threshold (red line at 20).
This setup helps monitor if our queue accumulates too many unprocessed messages, which could indicate processing delays or issues with the consumers.
Consumers refer to all our applications or system components that retrieve and process messages from the queue.
If the average message count goes above 20, you'll receive an alert, allowing you to investigate and take appropriate action to prevent backlogs in your queue.

Setting up CloudWatch alarms

Setting up CloudWatch alarms

Setting up CloudWatch alarms
The alarm for our SQSHandsOn queue is currently in an "Insufficient data" state. This means CloudWatch lacks enough information to determine if the alarm should trigger.
The graph shows no data points, indicating the queue is new. The alarm is triggered when the average message count exceeds 20 within 5 minutes.
CloudWatch will collect data and update the alarm state as the queue becomes active and messages are processed.
While SQS and SNS are both messaging services, they serve different purposes. This section clarifies the differences and use cases for each.

SNS versus SQS comparison table
Following best practices is important to getting the most out of SQS. These are some tips for optimal use:
AWS SQS is a powerful tool for building scalable and resilient cloud applications. By decoupling components of your application, you can achieve greater flexibility, fault tolerance, and scalability. With its ease of use, robust feature set, and integration with other AWS services, SQS is an essential service for modern cloud architectures.
Remember to monitor your usage, optimize your implementation, and follow best practices to get the most out of AWS SQS. As your application grows and evolves, SQS can adapt to your changing needs, making it a valuable asset in your AWS toolkit.
Continue your AWS journey by enrolling in our AWS Cloud Technology and Services course. This initial step will allow you to advance your career and later getting AWS certified.
A standard queue allows for unlimited throughput and at-least-once message delivery, with no guarantee of the order of messages. A FIFO queue, on the other hand, ensures that messages are processed in the exact order they are sent and guarantees that each message is processed only once.
You can control access to SQS queues using IAM policies and SQS resource policies. IAM policies allow you to manage permissions for users and roles, while SQS policies manage access at the queue level, restricting access to specific AWS accounts or actions.
AWS SQS costs are based on the number of API requests and data transfer. The first million requests each month are free, and pricing increases based on the number of requests and additional features like FIFO queues and long polling.
To optimize performance, use long polling to reduce empty receives, implement batch operations to send and receive messages in bulk, and monitor your queue with CloudWatch to adjust your message processing capacity as needed.
A multi-talented data scientist who enjoys sharing his knowledge and giving back to others, Zoumana is a YouTube content creator and a top tech writer on Medium. He finds joy in speaking, coding, and teaching . Zoumana holds two master’s degrees. The first one in computer science with a focus in Machine Learning from Paris, France, and the second one in Data Science from Texas Tech University in the US. His career path started as a Software Developer at Groupe OPEN in France, before moving on to IBM as a Machine Learning Consultant, where he developed end-to-end AI solutions for insurance companies. Zoumana joined Axionable, the first Sustainable AI startup based in Paris and Montreal. There, he served as a Data Scientist and implemented AI products, mostly NLP use cases, for clients from France, Montreal, Singapore, and Switzerland. Additionally, 5% of his time was dedicated to Research and Development. As of now, he is working as a Senior Data Scientist at IFC-the world Bank Group.
blog
blog
Samouczek
Learn more AWS with these courses!
Kurs
Poznaj świat Amazon Web Services (AWS) i dowiedz się, dlaczego jest liderem chmury obliczeniowej.
Kurs
Opanuj bezpieczeństwo, zarządzanie i optymalizację kosztów AWS, aby przygotować się do certyfikacji Cloud Practitioner.
Ścieżka
Przygotuj się do certyfikacji Amazon AWS Certified Cloud Practitioner (CLF-C02), ucząc się, jak korzystać z podstawowych usług obliczeniowych, baz danych i pamięci masowej AWS oraz jak je zabezpieczać.
Amazon Simple Queue Service (SQS) is a fully managed message queuing service provided by Amazon Web Services (AWS). It enables the decoupling and scaling distributed systems, microservices, and serverless applications.
This guide provides a clear understanding of AWS SQS, covering its features and the process of setting up and managing queues. It also discusses how to send and receive messages, examines pricing models, explores monitoring and metrics, compares SQS with SNS, and shares best practices for optimal use.
For those without background in AWS, our Introduction to AWS course is a good starting point. It helps you discover the world of Amazon Web Services and understand why it is at the forefront of cloud computing.
What is AWS SQS?
Before we dive into the details, let's first understand what AWS SQS is and why it's so valuable in the AWS ecosystem.
Amazon SQS architecture diagram
AWS SQS is a distributed queuing system that enables web service applications to quickly and reliably queue messages generated by producers to be consumed by consumers.
A queue serves as a temporary repository for messages awaiting processing. Amazon SQS also offers retry capabilities through its redrive policy, which allows for multiple retries and the use of dead letter queues (DLQs) used to manage error-prone messages by notifying developers of issues and optionally storing the messages for future reprocessing.
SQS features and benefits
Using SQS has several benefits including, and not limited to, the following:
AWS SQS key features and benefits
Use cases in decoupling and scaling microservices
Several industry use cases can leverage the benefits of SQS, and some of them are illustrated below:
AWS SQS use cases in decoupling and scaling microservices