com.amazonaws.SdkClientException : Unable to execute HTTP request: sts.amazonaws.com in GetSessionToken

7k Views Asked by At

Not found the exact root cause. This is happening while executing GetSessionToken and its inconsistent behavior. Could anyone know the root cause and possible fixes?

aws-java-sdk version 1.11.905

Executed code

AWSCredentials awsCredentials = new BasicAWSCredentials(accessKeyId, accessKeySecret);
AWSSecurityTokenService stsClient = AWSSecurityTokenServiceClientBuilder
                                    .standard()
                                    .withRegion("us-west-2") 
                                    .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
                                    .build();
// Start a new session for managing a service instance's bucket 
GetSessionTokenRequest getSessionTokenRequest = new GetSessionTokenRequest().withDurationSeconds(43200);
// Get the session token for the service instance's bucket 
// Error initiated from here 
sessionCredentials = stsClient.getSessionToken(getSessionTokenRequest).getCredentials();

Error:

com.amazonaws.SdkClientException : Unable to execute HTTP request: sts.amazonaws.com
com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleRetryableException(AmazonHttpClient.java:1207)
com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1153)
com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:802)
com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:770)
com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:744)
com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:704)
com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:686)
com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:550)
com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:530)
com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient.doInvoke(AWSSecurityTokenServiceClient.java:1652)
com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient.invoke(AWSSecurityTokenServiceClient.java:1619)
com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient.invoke(AWSSecurityTokenServiceClient.java:1608)
com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient.executeGetSessionToken(AWSSecurityTokenServiceClient.java:1546)
com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient.getSessionToken(AWSSecurityTokenServiceClient.java:1516)
1

There are 1 best solutions below

0
On

you can try setting

AWS_STS_REGIONAL_ENDPOINTS=regional

or other set region specific sts endpoint explicitly.

please see: https://docs.aws.amazon.com/sdkref/latest/guide/feature-sts-regionalized-endpoints.html