Example usage for com.amazonaws.auth BasicSessionCredentials BasicSessionCredentials

List of usage examples for com.amazonaws.auth BasicSessionCredentials BasicSessionCredentials

Introduction

In this page you can find the example usage for com.amazonaws.auth BasicSessionCredentials BasicSessionCredentials.

Prototype

public BasicSessionCredentials(String awsAccessKey, String awsSecretKey, String sessionToken) 

Source Link

Usage

From source file:org.zalando.stups.fullstop.plugin.example.ExamplePlugin.java

License:Apache License

private AmazonEC2Client getClientForAccount(final String accountId, final Region region) {
    AWSSecurityTokenServiceClient stsClient = new AWSSecurityTokenServiceClient(
            new ProfileCredentialsProvider());

    AssumeRoleRequest assumeRequest = new AssumeRoleRequest()
            .withRoleArn("arn:aws:iam::ACCOUNT_ID:role/fullstop-role").withDurationSeconds(3600)
            .withRoleSessionName("fullstop-role");

    AssumeRoleResult assumeResult = stsClient.assumeRole(assumeRequest);

    BasicSessionCredentials temporaryCredentials = new BasicSessionCredentials(
            assumeResult.getCredentials().getAccessKeyId(), assumeResult.getCredentials().getSecretAccessKey(),
            assumeResult.getCredentials().getSessionToken());

    AmazonEC2Client amazonEC2Client = new AmazonEC2Client(temporaryCredentials);
    amazonEC2Client.setRegion(region);//from ww w.ja v  a 2  s .com

    return amazonEC2Client;
}