AmazonS3ClientBuilder.defaultClient() 無法考慮地區?
2022-09-02 20:45:54
Amazon Java SDK 已将构造函数标记为已弃用,以支持某些 .但是,遵循该建议并不会导致AmazonS3客户端工作相同。特别是,客户端以某种方式未能考虑区域。如果运行以下测试,则测试将演示问题。AmazonS3Client
AmazonS3ClientBuilder.defaultClient()
thisFails
public class S3HelperTest {
@Test
public void thisWorks() throws Exception {
AmazonS3 s3Client = new AmazonS3Client(); // this call is deprecated
s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build());
assertNotNull(s3Client);
}
@Test
public void thisFails() throws Exception {
AmazonS3 s3Client = AmazonS3ClientBuilder.defaultClient();
/*
* The following line throws like 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.
*/
s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).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.
at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:371)
at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:337)
at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)
at com.amazonaws.services.s3.AmazonS3ClientBuilder.defaultClient(AmazonS3ClientBuilder.java:54)
at com.climate.tenderfoot.service.S3HelperTest.thisFails(S3HelperTest.java:21)
...
这是 AWS 开发工具包错误吗?是否有一些“区域默认提供程序链”或某种机制从环境中派生区域并将其设置为客户端?替换弃用的方法不会导致相同的功能,这似乎真的很弱。