I suck at introduction, so let the Pro does it!
Click Quick-Create Queue afterwards.
And that’s it! A SQS queue is created. A finish view of queue list.
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.
Input any text for testing and click Send Message.
Result showing message sent successfully.
Verify Messages Available value is changed.
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`"
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}’
From Console, go to Queue Actions and View/Delete Messages.
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.
Since this is a Standard queue, so messages in queue are randomly returned by ReceivedMessage request.
There are couple configurations available to the queue.
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.
Another setting is Receive Message Wait Time, which is used for long polling, which will dramatically cut down the cost of polling 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
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
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}’
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.