0

For getting s3 client object i am using below code.

BasicAWSCredentials creds = new BasicAWSCredentials(key, S3secretKey); 
AmazonS3 s3Client =AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(creds)).build();

Getting below errors

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.

Sonali Sahoo
  • 57
  • 1
  • 6

3 Answers3

4

I had to change to:

AmazonS3 client = AmazonS3ClientBuilder.standard()
                         .withRegion(Regions.US_EAST_1)
                         .withForceGlobalBucketAccess(true)
                         .build();

to emulate the "old" way (i.e. new AmazonS3Client() )

stdunbar
  • 16,263
  • 11
  • 31
  • 53
2

With a builder you need to provide your S3 bucket region using builder method, like .withRegion(Regions.US_EAST_1)

Drazen Nikolic
  • 508
  • 4
  • 14
0

One way to do it with the 1.11.98 version of the sdk, in your code, you would do:

AmazonS3 s3 = AmazonS3ClientBuilder.defaultClient();

And you need to have ~/.aws/credentials and ~/.aws/config files:

~/.aws/credentials contents:

[pca]
aws_access_key_id = KDDDJGIzzz3VVBXYA6Z
aws_secret_access_key = afafaoRDrJhzzzzg/Hhcccppeeddaf

[deault]
aws_access_key_id = AMVKNEIzzzNEBXYJ4m
aws_secret_access_key = bU4rUwwwhhzzzzcppeeddoRDrJhogA

~/.aws/config contents:

[default]
region = us-west-1

[pca]
region = us-west-1

Make sure they're readable, and that you export a profile if you have multiple as above before starting your service:

alper$ export AWS_PROFILE="pca"

There's a good description here

Alper Akture
  • 2,445
  • 1
  • 30
  • 44