2

I used the

AWSSecurityTokenServiceClient sts_client = new AWSSecurityTokenServiceClient(), 

and a default region (Global) was set authomatically. But this constructor is deprcated and the recommendation is to use:

AWSSecurityTokenServiceClientBuilder.

I want it to use a default region, as well. I wrote:

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

but I got an 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)

Thanks!

crooksey
  • 8,521
  • 6
  • 30
  • 52
Hadar
  • 21
  • 1
  • 3

1 Answers1

5

I've never heard of the Global region, but to specify a default region with the new non-deprecated Builder method, you can use:

.withRegion(Regions.DEFAULT_REGION)

So your command would be:

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

FYI - in my version of the Regions enum, DEFAULT_REGION is US_WEST_2. Don't forget to

import com.amazonaws.regions.Regions;

EDIT: It may be useful to know that it doesn't matter what region you specify. The generated STS credentials can be used in all regions (so they are 'global' in a sense).

Dylan
  • 338
  • 3
  • 16