There are two types of SQS, which are the Standard and FIFO. Start by giving queue a name, brief introduction is provided during creation and for this walk through, I used Standard Queue.

AWS SQS
AWS SQS

Click Quick-Create Queue afterwards.

AWS SQS

And that’s it! A SQS queue is created. A finish view of queue list.

AWS SQS

Notice that Messages Available column is showing 0 as there is no message in the queue right now. Let’s add a message to the queue.

AWS SQS

Input any text for testing and click Send Message.

AWS SQS

Result showing message sent successfully.

AWS SQS

Verify Messages Available value is changed.

AWS SQS

Use CLI to send message to the Queue. Please note that --profile is not necessary. It is used to tell CLI which AWS credential I am using to access AWS resources. The following command sends a unix time stamp as the message to the queue.

aws sqs send-message --queue-url https://sqs.us-east-1.amazonaws.com/UrAccountID/ystataws --profile UrName --output json --message-body “`date +%s`"

AWS SQS

Once the message is sent to the queue, let’s retrieve the message from both console and CLI. The following command only prints out the content of the body. Remove everything from --query to see full result.

aws sqs receive-message --queue-url https://sqs.us-east-1.amazonaws.com/UrAccountID/ystataws --profile UrName--output json --query ‘Messages[*].{Msg:Body}’

AWS SQS

From Console, go to Queue Actions and View/Delete Messages.

AWS SQS

Notice that only 10 messages are available for every ReceiveMessage request. AWS SQS has two ways to poll the message which are default short poll and long polling.

AWS SQS

Since this is a Standard queue, so messages in queue are randomly returned by ReceivedMessage request.

AWS SQS

There are couple configurations available to the queue.

AWS SQS

One of them is Default Visibility Timeout. Basically this is setting the time on the messages NOT visible to other ReceiveMessage request when the message itself is being pulling at the moment.

AWS SQS

Another setting is Receive Message Wait Time, which is used for long polling, which will dramatically cut down the cost of polling SQS.

AWS SQS

Now, from CLI, polling max of 10 messages at one time. In order to make this command work, make sure you have a lot of messages in a queue. AWS states that

Amazon SQS never returns more messages than this value (however, fewer messages might be returned). Valid values: 1 to 10. Default: 1.

From CLI, I have 108 messages in a queue.

aws sqs get-queue-attributes --queue-url https://sqs.us-east-1.amazonaws.com/UrAccountID/ystataws --profile UrName --output json --attribute-names ApproximateNumberOfMessages

AWS SQS

Polling maximum messages using CLI.

aws sqs receive-message --queue-url https://sqs.us-east-1.amazonaws.com/UrAccountID/ystataws --max-number-of-messages 10 --wait-time-seconds 20 --profile UrName --output json --query ‘Messages[*].{Msg:Body}’

AWS SQS

Lastly, let’s clean up the resource. I will delete a message from queue, purge all message from queue and lastly, delete the queue. In order to delete message, you need to use receive-message to get the ReceipHandle value.

Use delete-message to delete message.

aws sqs delete-message --queue-url https://sqs.us-east-1.amazonaws.com/UrAccountID/ystataws --receipt-handle AQEBVegNzXm7A74LFu5TJ0dln5+sH9BiBQRRMF2CzSs+mBlXUlhcmNuWjiZSsoq5iF0pX7q+jYU6Cv6IG6d3grYWeiU2nlEMHqxXhSXoa9wx/4SuOPZfmM0DGj/SJKTD2HpLRqqfh3zSDa8QS7l6JYRQboX1NiRswBZQWbuVqwVAWq6ES6vXfXv9Ke5N712JpsS+TRE/7HKbCetEycmQNAnqWxazV0mBG6RpkIayM7v+eP6QWLCeM/40dGG0TKbjEzDCZqlTLhs1/KxBrLWNBxtCu0Osopj+LGMDNNxgTxg0ZXVCPv/JyLw7+SOtNZi/Vi6wlLFaJ7aEYbALL0FXiPykdE6wocr2Lov9SANgxOFxOy6HS7PMrX79gmp7GIUjgFZC --profile UrName--output json

Purge all messages in a queue at once. Use get-queue-attributes to verify that no messages are in the queue and lastly, use delete-queue to delete the queue. No output means the action is successful. All those actions can be verified from console too.

--

--

Yst@IT
Yst@IT

Written by Yst@IT

Cloud Solution Architect, focusing on Oracle Cloud Infrastructure currently.

No responses yet