0
0
AWScloud~5 mins

SQS queue concept in AWS - Commands & Configuration

Choose your learning style9 modes available
Introduction
Sometimes apps need to talk to each other without waiting. SQS queues help by holding messages safely until the other app is ready to read them.
When you want to send orders from a website to a warehouse system without slowing down the website.
When you need to process tasks one by one in the background, like resizing images uploaded by users.
When different parts of your app run on separate servers and need to share information reliably.
When you want to handle sudden bursts of messages without losing any.
When you want to make sure messages are not lost even if one part of your system is down.
Commands
This command creates a new SQS queue named 'my-app-queue' where messages can be stored and retrieved.
Terminal
aws sqs create-queue --queue-name my-app-queue
Expected OutputExpected
{"QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/my-app-queue"}
--queue-name - Specifies the name of the queue to create
This command lists all the SQS queues in your AWS account to confirm the queue was created.
Terminal
aws sqs list-queues
Expected OutputExpected
{"QueueUrls": ["https://sqs.us-east-1.amazonaws.com/123456789012/my-app-queue"]}
This command sends a message with the text 'Hello from my app' to the queue so it can be processed later.
Terminal
aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-app-queue --message-body "Hello from my app"
Expected OutputExpected
{"MD5OfMessageBody": "8b1a9953c4611296a827abf8c47804d7", "MessageId": "1234abcd-56ef-78gh-90ij-klmnopqrstuv"}
--queue-url - Specifies the exact queue to send the message to
--message-body - The content of the message being sent
This command retrieves one message from the queue so your app can read and process it.
Terminal
aws sqs receive-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-app-queue
Expected OutputExpected
{"Messages": [{"MessageId": "1234abcd-56ef-78gh-90ij-klmnopqrstuv", "ReceiptHandle": "AQEB1234...", "MD5OfBody": "8b1a9953c4611296a827abf8c47804d7", "Body": "Hello from my app"}]}
--queue-url - Specifies the queue to receive messages from
This command deletes the message from the queue after it has been processed to avoid processing it again.
Terminal
aws sqs delete-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-app-queue --receipt-handle AQEB1234...
Expected OutputExpected
No output (command runs silently)
--queue-url - Specifies the queue where the message is located
--receipt-handle - Unique identifier for the message to delete
Key Concept

If you remember nothing else from this pattern, remember: SQS queues hold messages safely so apps can work at their own pace without losing data.

Common Mistakes
Trying to receive messages from the queue without specifying the correct queue URL.
The command will fail or return no messages because it doesn't know which queue to check.
Always include the exact queue URL with --queue-url when receiving or deleting messages.
Not deleting messages after processing them.
Messages stay in the queue and can be processed multiple times, causing duplicate work.
Use the delete-message command with the receipt handle after processing each message.
Using the queue name instead of the queue URL in commands that require the URL.
AWS CLI commands expect the full queue URL, not just the name, so the command will fail.
Use the queue URL returned when creating or listing queues for commands that need it.
Summary
Create an SQS queue with aws sqs create-queue to hold messages.
Send messages to the queue using aws sqs send-message with the queue URL.
Receive messages with aws sqs receive-message and process them.
Delete messages after processing with aws sqs delete-message to prevent duplicates.