0 votes
1 view
in AWS by (18.2k 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 (42.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();

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...