我使用aws-java-sdk版本1.11.104。按照AWS credentials doc默認的區域是us-east-1
,但是當我不用手動設置的區域,當我創建一個客戶端,就像這樣:以編程方式設置AWS區域
AWSCredentialsProvider awsCredentialsProvider =
new AWSStaticCredentialsProvider(new BasicAWSCredentials(awsAccessKey, awsSecretKey));
AmazonS3 s3Client =
AmazonS3ClientBuilder.standard().withCredentials(awsCredentialsProvider).build();
我得到這個錯誤:
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.
爲什麼不使用默認區域?
我試着在我的代碼之前添加以下內容,但它仍然不起作用。
System.setProperty(SDKGlobalConfiguration.AWS_REGION_ENV_VAR, "us-east-1");
如何編程設置AWS區域?(我想在運行時爲我的項目的所有類設置它)。
謝謝。
編輯:
我知道我可以在客戶的建設者用.withRegion()
,但我期待一個默認的區域,或者,該區域由一個環境變量通過默認區域提供環比回升。
第二個問題http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/client/builder/AwsClientBuilder.html#withRegion-com.amazonaws.regions.Regions- –
1日問題HTTP: //docs.aws.amazon.com/sdk-for-java/v1/developer-guide/java-dg-region-selection.html –
http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/ com/amazonaws/client/builder/AwsClientBuilder.html#setRegion-java.lang.String- – alfasin