Example usage for com.amazonaws.auth.profile ProfileCredentialsProvider getCredentials

List of usage examples for com.amazonaws.auth.profile ProfileCredentialsProvider getCredentials

Introduction

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

Prototype

@Override
    public AWSCredentials getCredentials() 

Source Link

Usage

From source file:com.dell.doradus.db.dynamodb.DynamoDBService.java

License:Apache License

private AWSCredentials getCredentials() {
    String awsProfile = getParamString("aws_profile");
    if (!Utils.isEmpty(awsProfile)) {
        m_logger.info("Using AWS profile: {}", awsProfile);
        ProfileCredentialsProvider credsProvider = null;
        String awsCredentialsFile = getParamString("aws_credentials_file");
        if (!Utils.isEmpty(awsCredentialsFile)) {
            credsProvider = new ProfileCredentialsProvider(awsCredentialsFile, awsProfile);
        } else {/*w  w w  .  j  a va  2s .  c om*/
            credsProvider = new ProfileCredentialsProvider(awsProfile);
        }
        return credsProvider.getCredentials();
    }

    String awsAccessKey = getParamString("aws_access_key");
    Utils.require(!Utils.isEmpty(awsAccessKey),
            "Either 'aws_profile' or 'aws_access_key' must be defined for tenant: " + m_tenant.getName());
    String awsSecretKey = getParamString("aws_secret_key");
    Utils.require(!Utils.isEmpty(awsSecretKey),
            "'aws_secret_key' must be defined when 'aws_access_key' is defined. "
                    + "'aws_profile' is preferred over aws_access_key/aws_secret_key. Tenant: "
                    + m_tenant.getName());
    return new BasicAWSCredentials(awsAccessKey, awsSecretKey);
}

From source file:oulib.aws.s3.S3Util.java

/**
 * Use the default approach to get a AWS S3 client with the default region of east.
 * /*  ww  w  .  j a v  a  2  s  .  co  m*/
 * @return AmazonS3 : s3 client
 */
public static AmazonS3 getS3AwsClient() {

    AWSCredentials credentials = null;
    try {
        ProfileCredentialsProvider provider = new ProfileCredentialsProvider("default");
        credentials = provider.getCredentials();
        if (null == credentials) {
            throw new InvalidS3CredentialsException("Invalid credentials with default approach!");
        }
    } catch (InvalidS3CredentialsException | AmazonClientException e) {
        throw new AmazonClientException("Cannot load the credentials from the credential profiles file. "
                + "Please make sure that your credentials file is at the correct "
                + "location (/Users/zhao0677/.aws/credentials), and is in valid format.", e);
    }

    AmazonS3 s3client = new AmazonS3Client(credentials);
    Region usEast = Region.getRegion(Regions.US_EAST_1);
    s3client.setRegion(usEast);
    return s3client;
}