Search in sources :

Example 1 with AWSSecurityTokenService

use of com.amazonaws.services.securitytoken.AWSSecurityTokenService in project eureka by Netflix.

the class AwsAsgUtil method initializeStsSession.

private Credentials initializeStsSession(String asgAccount) {
    AWSSecurityTokenService sts = new AWSSecurityTokenServiceClient(new InstanceProfileCredentialsProvider());
    String region = clientConfig.getRegion();
    if (!region.equals("us-east-1")) {
        sts.setEndpoint("sts." + region + ".amazonaws.com");
    }
    String roleName = serverConfig.getListAutoScalingGroupsRoleName();
    String roleArn = "arn:aws:iam::" + asgAccount + ":role/" + roleName;
    AssumeRoleResult assumeRoleResult = sts.assumeRole(new AssumeRoleRequest().withRoleArn(roleArn).withRoleSessionName("sts-session-" + asgAccount));
    return assumeRoleResult.getCredentials();
}
Also used : InstanceProfileCredentialsProvider(com.amazonaws.auth.InstanceProfileCredentialsProvider) AssumeRoleRequest(com.amazonaws.services.securitytoken.model.AssumeRoleRequest) AWSSecurityTokenServiceClient(com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient) AssumeRoleResult(com.amazonaws.services.securitytoken.model.AssumeRoleResult) AWSSecurityTokenService(com.amazonaws.services.securitytoken.AWSSecurityTokenService)

Aggregations

InstanceProfileCredentialsProvider (com.amazonaws.auth.InstanceProfileCredentialsProvider)1 AWSSecurityTokenService (com.amazonaws.services.securitytoken.AWSSecurityTokenService)1 AWSSecurityTokenServiceClient (com.amazonaws.services.securitytoken.AWSSecurityTokenServiceClient)1 AssumeRoleRequest (com.amazonaws.services.securitytoken.model.AssumeRoleRequest)1 AssumeRoleResult (com.amazonaws.services.securitytoken.model.AssumeRoleResult)1