Example usage for com.amazonaws.auth InstanceProfileCredentialsProvider getCredentials

List of usage examples for com.amazonaws.auth InstanceProfileCredentialsProvider getCredentials

Introduction

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

Prototype

@Override
public AWSCredentials getCredentials() 

Source Link

Usage

From source file:com.erudika.para.utils.Config.java

License:Apache License

private static String[] getAwsCredentials() {
    InstanceProfileCredentialsProvider ipcp = new InstanceProfileCredentialsProvider();
    try {/*from  w ww  .  j  ava  2  s .co  m*/
        ipcp.refresh();
        return new String[] { ipcp.getCredentials().getAWSAccessKeyId(),
                ipcp.getCredentials().getAWSSecretKey() };
    } catch (Exception e) {
        return new String[] { "", "" };
    }
}

From source file:com.yahoo.athenz.zms.store.impl.AWSObjectStoreFactory.java

License:Apache License

String getAuthToken(String hostname, int port, String rdsUser, String rdsIamRole) {

    InstanceProfileCredentialsProvider awsCredProvider = new InstanceProfileCredentialsProvider(true);

    if (LOG.isDebugEnabled()) {
        LOG.debug("getAuthToken: Access key id: {}", awsCredProvider.getCredentials().getAWSAccessKeyId());
    }//from   w w  w .  java 2  s . c om

    RdsIamAuthTokenGenerator generator = RdsIamAuthTokenGenerator.builder().credentials(awsCredProvider)
            .region(EC2MetadataUtils.getEC2InstanceRegion()).build();

    if (LOG.isDebugEnabled()) {
        LOG.debug("Instance {} Port {} User {} Region: {} Role: {}", hostname, port, rdsUser,
                EC2MetadataUtils.getEC2InstanceRegion(), rdsIamRole);
    }

    return generator.getAuthToken(
            GetIamAuthTokenRequest.builder().hostname(hostname).port(port).userName(rdsUser).build());
}