Code Robo
Java Code Complience
Virtual Service
Java Code To Connect Amazon Simple Queue Service(SQS) Service
       Talk to EasyAssistant

It provides the steps to connect AWS Glacier service and create vault, delete vault, upload zip file to vault and download files from Glacier valuts. One sample example with java code is shown for Java platform using AWS JAVA SDK library. Sample code uses aws-java-sdk-1.0.12 library provided by AWS. This java code is very sort and simple so that user can understand easily.

This java code connect AWS SQS(Simple Queue Service) service and get the list of the Queues and read the message from the queue as well as post to the message to the queue. Current program can be extended to asynchronous communication with the queue. From my experience what I noticed that people face the difficulties to coneect the queue of the AWS SQS service from Java client. But once the able to connect, they can easy do other operation with the queue as well as manage the queue . This program will guide you on how to connect SQS service from thrid part (external) program / service to manage the resources in SQS. This code can be copied, compiled and run on eclipse or any other Java IDE. You just need to have AWS java sdk jars added in your class path.

Sample Java Code To Connect queue in SQS service of AWS:

package easycodeforall.client;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Regions;

public class ConnectAwsSQS {

	public static void main(String[] args) {

		System.out.println("Conneting AWS Amazon  SQS Service");
		String accessKeyID = "AKI*************37";// You get it form AWS Console /
		// You get it form AWS Console
		String secretAccessKey = "Mys*************************LSaV";
		AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyID, secretAccessKey);

		AmazonSQS awsSQS = AmazonSQSClientBuilder.standard()
				.withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).withRegion(Regions.US_EAST_1)

		System.out.println("sqs.listQueues();=" + awsSQS.listQueues());

		ListQueuesResult results = awsSQS.listQueues();



	public static void readMessageFromQ(AmazonSQS awsSQS) {

		ReceiveMessageRequest readMessageRequestFromStdQueue = new ReceiveMessageRequest();

		List sqsMessages = awsSQS.receiveMessage(readMessageRequestFromStdQueue).getMessages();
		for (Message msg : sqsMessages) {

			System.out.println("Message Body=" + msg.getBody());
			System.out.println("Message Id=" + msg.getMessageId());
		System.out.println("Message received from DDR_easy queue ");

	public static void postMessageToStandardQ(AmazonSQS awsSQS) {

		SendMessageRequest messagePostRequestToStandardQueue = new SendMessageRequest();
		messagePostRequestToStandardQueue.setMessageBody("Message Posted By Easycodeforall");

		MessageAttributeValue msgAttributeValue = new MessageAttributeValue();
		Map map = new HashMap();
		map.put("one", msgAttributeValue);
		System.out.println("Message posted to DDR_easy queue ");



Now question is how we can get the accessKeyID and secretAccessKey and URL of the Queue

1. Create a Policy for SQS service as shown below.

Create SQS Policy

2. Create a IAM User along with accessKey to access SQS service as shown below

Create user and access key, secret key

You can create access key after creating the user. it will ask you to create a access key. Just click on that, it will create the access key and secret key.

Create user and access key, secret key

Create user and access key, secret key

Create user and access key, secret key

4. Assign the policy to the user which you created in the above step

Attach Policy With the User

Attach Policy With the User

Please provide your feedback here
It has been explained in this video ( Please watch it.

Post Your Comment:
Name :
Email ( Optional) :
Comments / Suggestion (* Required) It is required: :