Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in AWS by (19.1k points)

I am using AWS Java API for S3. The access key, secret key, bucket name, and region name are all provided to my application as environment variables.

I am not sure how to set the region name...I'm currently getting the AmazonS3Client

return new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey))

Can someone please tell me how to set the region name?

1 Answer

0 votes
by (44.4k points)

Notice that if you have the region as a string, you can do this:

Regions regions = Regions.fromName('us-west-1');

And you can create a credentials provider in a variety of ways, including this:

AWSStaticCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(

        new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY));

and then (for whatever builder you're doing), you can do this:

AmazonSNS snsClient = AmazonSNSClientBuilder.standard()

    .withRegion(region)

    .withCredentials(credentialsProvider)

    .build();

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories

...