2

我用

AWSSecurityTokenServiceClient sts_client = new AWSSecurityTokenServiceClient(), 

并自动设置了默认区域(全局)。但是此构造函数已弃用,建议使用:

AWSSecurityTokenServiceClientBuilder.

我也希望它使用默认区域。我写:

AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).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 co.softimize.STSManager.<init>(STSManager.java:31)
at co.softimize.sts.STSManagerTests.setup(STSManagerTests.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

谢谢!

4

1 回答 1

5

我从未听说过 Global 区域,但要使用新的非弃用 Builder 方法指定默认区域,您可以使用:

.withRegion(Regions.DEFAULT_REGION)

所以你的命令是:

AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider(awsCredentials)) .withRegion(Regions.DEFAULT_REGION.getName()) .build();

仅供参考 - 在我的 Regions 枚举版本中,DEFAULT_REGIONUS_WEST_2. 不要忘记

import com.amazonaws.regions.Regions;

编辑:知道您指定的区域无关紧要可能很有用。生成的 STS 凭证可以在所有地区使用(因此它们在某种意义上是“全球性的”)。

于 2017-07-12T22:49:04.960 回答