2
votes

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

2

2 Answers

4
votes

I setup the aws sqs client this way:

BasicAWSCredentials bAWSc = new BasicAWSCredentials(accessKey, secretKey);
return AmazonSQSClientBuilder.standard().withRegion(region).withCredentials(new AWSStaticCredentialsProvider(bAWSc)).build();
0
votes

based on what @Francesco put, I created a more intuitive version

BasicAWSCredentials bAWSc = new BasicAWSCredentials(accessKey, secretKey);
final AmazonSQS sqs = AmazonSQSClientBuilder.standard()
        .withRegion(Regions.US_EAST_1)
        .withCredentials(new AWSStaticCredentialsProvider(bAWSc ))
        .build();