Amazon SQS : A Queue Service by AWS

Are you preparing for AWS Certified Developer Associate certification exam? In this space, we are writing series of articles on topics which are covered in the developer associate certification exam. In this article, we are explaining one of the important concept Simple Queue Service (Amazon SQS). You would expect few questions from this topic for developer associate exam. You can subscribe to us for receiving the further updates on this topic.

What is AWS SQS?

Developer Associate certification exam is the most easiest exam in the associate level, it is good idea to start your certification from this exam. Also we would recommend you to pass the AWS Certified Solutions Architect certification exam which covers the concepts of all the services offered in AWS.

Developer Associate Syllabus

Here is the snapshot of blueprint for developer associate is covered in the developer associate exam.

aws-developer-associate-blueprint

Amazon SQS

Amazon SQS is a fully managed queue service provided by AWS. Some of the key features of Amazon SQS are

  • Its simple to use. It has a web interface which allows one to easily manage and work with queues.
  • It helps decouple components of an application. So if you want to add scalability to your application, adding SQS as a component can greatly help.
  • It is scalable. You can transmit any volume of data and at any level of throughput. You don’t need to worry about the working of the queue service itself. AWS will automatically ensure that the load can be taken when the message has a lot of messages added to it.
  • Availability of SDK – SQS has a lot of API’s available which can be used to work with queues. Some of them are given below
    • CreateQueue – This API can be used to create a queue in SQS.
    • SendMessage – This API can be used to send a message to an existing queue in SQS.
    • ReceiveMessage – This API can be used to receive a message from an existing queue in SQS.
    • DeleteMessage – This API can be used to delete a message from an existing queue in SQS.

One of the key aspects for the Developer exam is to know how to setup queues and use the API’s to work with the queues.

Working with Queues in SQS

First before we work on the API’s, let’s see how to work with the various SQS functionality from the aws dashboard.

  • Creating a queue – Log into your AWS Console. You will see Simple Queue Service under the Messaging option.

aws-sns-messaging-option

 

  • Click on Create New Queue to create a queue in SQS.

AWS SQS - Create New Queue

  • Give a name for the queue and values for the different settings of the queue.

AWS SQS - Queue Inputs

The different parameters of the queue are explained below as follows

    • Default Visibility Timeout – This is the timeout on when a message will not be visible after the message is read from the queue. Ideally the message should be processed and deleted during this interval.
    • Message Retention Period – This is the time in which the message should remain in the queue. The default time is 4 days. So any message older than 4 days gets deleted.
    • Maximum message size – This is the maximum size of the message.
    • Delivery Delay – This is the delay in which messages sent to the queue will not be visible to consumers of the queue.
    • Receive Message Wait time – When this is set to 0 seconds, then this is called as short polling. This means that AWS will keep on polling the queues to see if messages are present. There is also the concept of long polling wherein you don’t need to poll the queue every time. For this you need to set the value of this parameter to a value greater than 0 and less or equal to 20.
  • Once the queue is created, if you want to add messages to the queue, click on the desired queue and click on the ‘Send a Message’ option.

AWS SQS - Add message to Queue

Give a value for the message and click on the ‘Send Message’ button.

AWS SQS - Send Message

  • Next choose the queue and click on View/Delete Messages

AWS SQS - View/Delete Message

  • Click on ‘Start polling for messages”

AWS SQS - Polling Message

  • The message created earlier will then be visible in the queue. If you want you can click on ‘More details’ or click on Delete Message to delete the message from the queue.

AWS SQS - Message Created

Working with SQS from CLI

Now that we have seen how to work with SQS via the dashboard, let’s now work with queues on the command line interface.

The installation for the command line interface is present in the following url

http://docs.aws.amazon.com/cli/latest/userguide/installing.html

If you are on the windows system, you can then work with the CLI via powershell.

  • First make sure to issue the as configure to ensure powershell works with AWS. Here you have to specify the access key ID and Secret access key.

AWS SQS - Windows Powershell

  • If you want to get the url for your queue, you can issue the below command

aws sqs –region ap-southeast-1 get-queue-url –queue-name Demo

In the above command you are mentioning the region via the –region parameters. Also the option to get the queue url is the get-queue-url option. Then you just need to specify the queue name.

AWS SQS - Specify Queue name

 

  • Let’s say that we want to send a message to the queue with the text of “Test Message2”, we can do this via the following command in powershell

aws sqs send-message –queue-url https://ap-southeast-1.queue.amazonaws.com/085363624145/Demo —   mesage-body “Test Message2”

So here you need to specify the send-message option to send the message to the queue. Then you need to mentioned the queue name and the body of the message that needs to be sent to SQS.

AWS SQS - Send Message to Queue from Powershell

You will then get the MessageID of the message created.

If you go to the SQS dashboard in the AWS console , you will be able to see the newly created message.

AWS SQS - Dashboard

  • If you want to retrieve a message via powershell , then you need to execute the below command

aws sqs receive-message –queue-url https://ap-southeast-1.queue.amazonaws.com/085363624145/Demo –attribute-names All –message-attribute-names All –max-number-of-messages 10

Here we need to mention the queue url, along with the fact that we want to retrieve all messages with all the attributes. We can mention to the limit the number of messages to return via the max-number-of-messages parameter.

This will retrieve all the messages and also retrieve the content of the messages

AWS SQS - Retrieve the content of messages

Final Points to Remember about SQS

  • It is designed for de-coupling of applications.
  • It is designed for scalability. You don’t need to worry when sending a large number of messages.
  • There are large number of API’s which can be used to work with SQS queues.
  • You can use the aws sqs get-queue-url to get the url of the queue in AWS. This can then be used in subsequent operation in SQS.
  • Next you can send a message to a queue via the send-message API of SQS
  • Next you can retrieve messages from a queue via the receive-message API of SQS
  • Remember the following parameters for the SQS queue because they are important for the exam
    • Default Visibility Timeout – This is the timeout on when a message will not be visible after the message is read from the queue. Ideally the message should be processed and deleted during this interval.
    • Message Retention Period – This is the time in which the message should remain in the queue. The default time is 4 days. So any message older than 4 days gets deleted.
    • Receive Message Wait time – When this is set to 0 seconds, then this is called as short polling. This means that aws will keep on polling the queues to see if messages are present. There is also the concept of long polling wherein you don’t need to poll the queue every time. For this you need to set the value of this parameter to a value greater than 0 and less or equal to 20.

Summary

In this article we have explained about how to use Simple QueueService (Amazon SQS). This is one of the most important service offered by Amazon Web Services (AWS). You would expect lot of questions from this topic in your certification exam.

If you are preparing for the AWS certifications exam and looking for any help, please send us a mail to call to our customer support team. 

About Pavan Gumaste

Pavan Rao is a programmer / Developer by Profession and Cloud Computing Professional by choice with in-depth knowledge in AWS, Azure, Google Cloud Platform. He helps the organisation figure out what to build, ensure successful delivery, and incorporate user learning to improve the strategy and product further.

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top