I use aws-java-sdk version 1.11.104. According to the AWS credentials doc the default region is us-east-1
, however when I don't set the region manually when I create a client, like this:
AWSCredentialsProvider awsCredentialsProvider =
new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsAccessKey, awsSecretKey));
AmazonS3 s3Client =
AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider).build();
I get this error:
com.amazonaws.SdkClientException:
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.
Why isn't the default region used?
I tried to add the following before my code above but it still doesn't work.
System.setProperty(SDKGlobalConfiguration.AWS_REGION_ENV_VAR, "us-east-1");
How to set the AWS region programmatically? (I would like to set it at runtime for all classes of my project).
Thanks.
Edit:
I know I can use .withRegion()
on the clients' builder, but I was expecting a default region, or, the region picked from an environment variable through the default region provider chain.