ArchiveTransferManagerBuilder无法通过区域提供商链

时间:2017-10-27 06:04:15

标签: java amazon-web-services amazon-glacier aws-java-sdk

即使我具体指定了该区域,AWS Glacier API也会向我发出错误信息:

EndpointConfiguration endpointConfig = new EndpointConfiguration("https://glacier.us-east-2.amazonaws.com/", "us-east-2");

AmazonGlacier glacierClient = AmazonGlacierClientBuilder.standard()
  .withEndpointConfiguration(endpointConfig)
  .withCredentials(credentials)
  .build();

ArchiveTransferManager xferMgr = new ArchiveTransferManagerBuilder()
    .withGlacierClient(glacierClient)
    .build();

    UploadResult result = xferMgr.upload("Data_Full", "my archive " + (new Date()), new File("C:\\myBigFile"));

我得到了这个堆栈跟踪:

  

com.amazonaws.SdkClientException:无法通过区域提供程序链查找区域。必须在构建器中提供显式区域   或设置环境以提供区域。在   com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:371)     在   com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:337)     在   com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46)     在   com.amazonaws.services.sqs.AmazonSQSClientBuilder.defaultClient(AmazonSQSClientBuilder.java:44)     在   com.amazonaws.services.glacier.transfer.ArchiveTransferManagerBuilder.resolveSQSClient(ArchiveTransferManagerBuilder.java:129)     在   com.amazonaws.services.glacier.transfer.ArchiveTransferManagerBuilder.getParams(ArchiveTransferManagerBuilder.java:135)     在   com.amazonaws.services.glacier.transfer.ArchiveTransferManagerBuilder.build(ArchiveTransferManagerBuilder.java:143)

请注意,我使用API​​列出保险库并且它可以工作:

AmazonGlacierClientBuilder clientbuilder = AmazonGlacierClientBuilder.standard();
EndpointConfiguration endpointConfig = new EndpointConfiguration("https://glacier.us-east-2.amazonaws.com/", "us-east-2");
clientbuilder.withEndpointConfiguration(endpointConfig);
ProfilesConfigFile cf = new ProfilesConfigFile();
AWSCredentialsProvider credentials = new ProfileCredentialsProvider(cf, "My AWS Profile Name");
clientbuilder.setCredentials(credentials);
AmazonGlacier glacierClient = CustomAmazonGlacierClientBuilder.buildCustomAmazonGlacierClient();
ListVaultsRequest request = new ListVaultsRequest();
ListVaultsResult result = glacierClient.listVaults(request);

我最近将AWS / Glacier库下载为Eclipse插件。它显示了.jar版本的aws-java-sdk-opensdk-1.11.130.jar

有没有人知道我可以在代码中添加什么来满足区域要求?我宁愿以编程方式做到这一点

1 个答案:

答案 0 :(得分:3)

我通过添加AWS_REGION环境变量解决了这个问题。例如。美国东部-2。使用Eclipse时,可以使用Run - >添加它。运行配置。

我还使用Eclipse帮助更新了Eclipse和AWS Eclipse插件 - >检查更新功能。