Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting AWS region programmatically for SQS

I just started working on AWS SDK for Java and .net.

currently i am creating a AWS SQS Queue. I was able to Create a QUEUE, List the existing queues, and talk to the queues with .net SDK.

When i tried the same with the java i m getting following error.

Unable to find a region via the region provider chain. Must provide an explicit region in the builder or setup environment to supply a region. I have set all the necessary access keys, Region and credentials in the aws preferences in eclipse.

This is how i am initializing SQS client in a Java maven project

  AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

I have googled and found that there is a key word called withregion() for S3 where i can specify the region but its not there for SQS.

I also tried setting region as

  sqs.setRegion(Region.AP_Mumbai);

This shows up following exception

The method setRegion(com.amazonaws.regions.Region) in the type AmazonSQS is not applicable for the arguments (com.amazonaws.services.s3.model.Region)

i tried setting the same using com.amazonaws.regions.Region but there is no provision as such.

Please Suggest

like image 469
vikas Avatar asked Sep 07 '25 15:09

vikas


1 Answers

I setup the aws sqs client this way:

BasicAWSCredentials bAWSc = new BasicAWSCredentials(accessKey, secretKey);
return AmazonSQSClientBuilder.standard().withRegion(region).withCredentials(new AWSStaticCredentialsProvider(bAWSc)).build();
like image 104
Francesco Avatar answered Sep 09 '25 06:09

Francesco