skip to Main Content

I am trying to use session token using AWS sts_client

AWSSecurityTokenService sts_client =  AWSSecurityTokenServiceClientBuilder.standard()
                                             .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("https://sts.ap-southeast-2.amazonaws.com", "ap-southeast-2"))
                                             .withRegion(Regions.AP_SOUTHEAST_2).build();
    

getting below error.

java.lang.IllegalStateException: Only one of Region or EndpointConfiguration may be set.
    at com.amazonaws.client.builder.AwsClientBuilder.setRegion(AwsClientBuilder.java:450) ~[aws-java-sdk-core-1.12.234.jar:na]
    at com.amazonaws.client.builder.AwsClientBuilder.configureMutableProperties(AwsClientBuilder.java:424) ~[aws-java-sdk-core-1.12.234.jar:na]
    at com.amazonaws.client.builder.AwsSyncClientBuilder.build(AwsSyncClientBuilder.java:46) ~[aws-java-sdk-core-1.12.234.jar:na]
    at 

2

Answers


  1. You have to use Amazon STS for temporary credentials. You get those credentials, including token, using for example AssumeRole.

    Login or Signup to reply.
  2. This below code working for me:

    AWSCredentials credentials = new BasicAWSCredentials("—-ACESSKEY—-",
    "—SECRET ACCESS KEY");

        AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
    
        AssumeRoleRequest assumeRequest = new AssumeRoleRequest()
                .withRoleArn("--------RoleArn----------")
                .withDurationSeconds(3600).withRoleSessionName("TEST");
    
        AWSSecurityTokenService securityTokenService = AWSSecurityTokenServiceClientBuilder.standard()
                .withRegion(Regions.US_EAST_1).withCredentials(credentialsProvider).build();
    
        AssumeRoleResult result = securityTokenService.assumeRole(assumeRequest);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search