From my local aws-cli i can get attributes and get queueUrl of a given queue. Whereas I am not able to get that function working from an adhoc spring application. This is just a trial code. We do have config to get connected to AWS SQS. Can someone help me on this?
Flow looks like- Application A(On-prem application) calls Credential Service to get token details which is having assume role set up. Application A then uses that token details to connect to AWS and read from SQS. I am able to connect to AWS but when trying to do getUrl getting exception.
Role allowance in AWS-
{ "Version": "2012-10-17", "Statement": [ { "Action": [ "sqs:" ], "Resource": "", "Effect": "Allow" } ] }
Working command-
aws sqs get-queue-attributes --queue-url --attribute-names All --region us-east-1
Sample Java Code-
AmazonSQS sqs = AmazonSQSClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(credentials))
.withRegion(Regions.US_EAST_1).build();
String queueUrl = "";
try {
queueUrl = sqs.getQueueUrl("queue-name").getQueueUrl();
} catch (Exception e) {
System.out.println(e);
}
ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest(queueUrl).withWaitTimeSeconds(10)
.withMaxNumberOfMessages(10);
List<Message> sqsMessages = sqs.receiveMessage(receiveMessageRequest).getMessages();
for (Message message : sqsMessages) {
System.out.println("Received vice message from sqs - " + message.getBody() + ". Message ReceiptHandle - "
+ message.getReceiptHandle());
}
Exception receiving-
An error occurred (AWS.SimpleQueueService.NonExistentQueue) when calling the GetQueueUrl operation: The specified queue does not exist or you do not have access to it.