How to Create an SQS Queue with AWS CLI
Introduction
Amazon Simple Queue Service (SQS) is a fully managed message queuing service that makes it easy to decouple and scale microservices, distributed systems, and serverless applications. SQS eliminates the complexity and overhead associated with managing and operating message-oriented middleware, and empowers developers to focus on differentiating work.
In this lesson, we will learn how to create an SQS queue with AWS CLI. We will cover the basics of SQS, the different types of queues, and how to create an SQS queue with AWS CLI.
What is SQS?
Amazon Simple Queue Service (SQS) is a fully managed message queuing service that makes it easy to decouple and scale microservices, distributed systems, and serverless applications. SQS eliminates the complexity and overhead associated with managing and operating message-oriented middleware, and empowers developers to focus on differentiating work.
SQS provides a reliable, highly scalable, hosted queue for storing messages as they travel between applications or microservices. It offers two types of message queues: standard and FIFO (first-in, first-out).
Types of SQS Queues
There are two types of SQS queues: standard and FIFO (first-in, first-out).
Standard queues provide best-effort ordering which ensures that messages are generally delivered in the same order as they are sent. Standard queues also support multiple readers and writers interacting with the same queue.
FIFO queues guarantee that messages are delivered and processed in the exact order in which they are sent. FIFO queues also support exactly-once processing, which ensures that each message is delivered once and remains available until a consumer processes and deletes it.
Creating an SQS Queue with AWS CLI
Now that we have a basic understanding of SQS, let’s learn how to create an SQS queue with AWS CLI.
Prerequisites
Before we begin, you will need to have the following prerequisites in place:
- An AWS account
- The AWS CLI installed and configured
Step 1: Create an SQS Queue
The first step is to create an SQS queue. To do this, we will use the aws sqs create-queue
command.
The following command will create a standard queue named my-queue
:
aws sqs create-queue --queue-name my-queue
The following command will create a FIFO queue named my-queue.fifo
:
aws sqs create-queue --queue-name my-queue.fifo --attributes '{"FifoQueue": "true"}'
Step 2: Get the Queue URL
Once the queue has been created, we need to get the queue URL. To do this, we will use the aws sqs get-queue-url
command.
The following command will get the queue URL for the queue named my-queue
:
aws sqs get-queue-url --queue-name my-queue
Step 3: Send a Message to the Queue
Now that we have the queue URL, we can send a message to the queue. To do this, we will use the aws sqs send-message
command.
The following command will send a message to the queue named my-queue
:
aws sqs send-message --queue-url <queue-url> --message-body "Hello World!"
Step 4: Receive a Message from the Queue
Now that we have sent a message to the queue, we can receive a message from the queue. To do this, we will use the aws sqs receive-message
command.
The following command will receive a message from the queue named my-queue
:
aws sqs receive-message --queue-url <queue-url>
Step 5: Delete a Message from the Queue
Once we have received a message from the queue, we can delete the message from the queue. To do this, we will use the aws sqs delete-message
command.
The following command will delete a message from the queue named my-queue
:
aws sqs delete-message --queue-url <queue-url> --receipt-handle <receipt-handle>
Conclusion
In this lesson, we learned how to create an SQS queue with AWS CLI. We covered the basics of SQS, the different types of queues, and how to create an SQS queue with AWS CLI. We also learned how to send and receive messages from the queue, and how to delete a message from the queue.