gpt4 book ai didi

aws-sts - AWS - STS 如何将 AWSSecurityTokenServiceClientBuilder 与全局区域结合使用

转载 作者:行者123 更新时间:2023-12-02 03:54:50 30 4
gpt4 key购买 nike

我用的是

AWSSecurityTokenServiceClient sts_client = new AWSSecurityTokenServiceClient(), 

并且自动设置默认区域(全局)。但这个构造函数已被弃用,建议使用:

AWSSecurityTokenServiceClientBuilder.

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

AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials)).build();

但我有一个异常(exception):

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)

谢谢!

最佳答案

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

.withRegion(Regions.DEFAULT_REGION)

所以你的命令是:

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

仅供引用 - 在我的 Regions 枚举版本中,DEFAULT_REGIONUS_WEST_2。别忘了

导入 com.amazonaws.regions.Regions;

编辑:了解您指定的区域并不重要可能会很有用。生成的STS凭证可以在所有区域使用(因此它们在某种意义上是“全局”的)。

关于aws-sts - AWS - STS 如何将 AWSSecurityTokenServiceClientBuilder 与全局区域结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44364357/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com