How to Create & Configure Simple Queue Service(SQS) on Amazon Web Service(AWS).
Amazon SQS provides queues for high-throughput, system-to-system messaging.We can use queues to decouple heavy weight processes and to buffer and batch work.
Amazon SQS is a web service that gives you access to a message queue that can be used to store messages while waiting for a computer to process them.
- Login to aws portal.
- Click on Services.
- Under Application Integration select Simple Queue Service.
- Click on Create Queue.
- Select Queue Type: FIFO(first-in,first-out) or Standard. Standard provide at-least-once message delivery, which means that each message is delivered at least once.
- FIFO provide exactly-once message delivery, which means that each message is delivered once and remains available until a consumer processes it and deletes it.
- Provide Queue name.
- Set maximum message size, visibility,& message retention.
- Set access policy who can send or receive message.
- Amazon SQS provides in-transit encryption method.
- We can send un-deliverable message to a dead-letter queue. By default,it is disabled.
- Provide tag key name & value.
- Click on Create queue.
- After sometime Queue created successfully.
- Click on Subscribe to Amazon SNS topic
- Provide exisitng Amazon SNS topic ARN.First create Amazon SNS topic so click on link https://www.hackerxone.com/blog/how-create-configure-simple-notification-servicesns-amazon-web-serviceaws for how to create Amazon SNS topic.
- Click on Save.
- Once Subscribe to Amazon SNS topic is done, Click on Send & Receive Message.
- Provide Message Body,
- Set message Attributes.
- Click on Send Message.
- Message has been sent & is ready to be received.
Create Simple Queue Service using Shell
- Setup aws-cli on your system so click on link https://www.hackerxone.com/blog/how-install-configure-aws-cli-ubuntu-1804
- Run the following command:
To create a queue
aws sqs create-queue –queue-name Queue-Name –attributes /path/of/create-queue.json
The create-queue.json file is given below:
{
“RedrivePolicy”: “{\”deadLetterTargetArn\”:\”arn:aws:sqs:us-east-1:80398EXAMPLE:MyDeadLetterQueue\”,\”maxReceiveCount\”:\”1000\”}”,
“MessageRetentionPeriod”: “259200”
}
To send a message
aws sqs send-message –queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue –message-body “example” –delay-seconds 10 –message-attributes /path/of/send-message.json
The send-message.json file is given below:
“City”: {
“DataType”: “String”,
“StringValue”: “Any City”
},
“Greeting”: {
“DataType”: “Binary”,
“BinaryValue”: “Hello, World!”
},
“Population”: {
“DataType”: “Number”,
“StringValue”: “1250800”
}
}
To receive a message
aws sqs receive-message –queue-url https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyQueue –attribute-names All –message-attribute-names All –max-number-of-messages 10