Example usage for com.amazonaws.auth InstanceProfileCredentialsProvider InstanceProfileCredentialsProvider

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

Introduction

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

Prototype

@Deprecated
public InstanceProfileCredentialsProvider() 

Source Link

Usage

From source file:com.netflix.eureka.aws.AwsAsgUtil.java

License:Apache License

private AmazonAutoScaling getAmazonAutoScalingClient() {
    String aWSAccessId = serverConfig.getAWSAccessId();
    String aWSSecretKey = serverConfig.getAWSSecretKey();
    ClientConfiguration clientConfiguration = new ClientConfiguration()
            .withConnectionTimeout(serverConfig.getASGQueryTimeoutMs());

    if (null != aWSAccessId && !"".equals(aWSAccessId) && null != aWSSecretKey && !"".equals(aWSSecretKey)) {
        return new AmazonAutoScalingClient(new BasicAWSCredentials(aWSAccessId, aWSSecretKey),
                clientConfiguration);//from  w  ww  .j  a v  a  2 s.  c  o m
    } else {
        return new AmazonAutoScalingClient(new InstanceProfileCredentialsProvider(), clientConfiguration);
    }
}

From source file:com.netflix.eureka.aws.EIPManager.java

License:Apache License

/**
 * Gets the EC2 service object to call AWS APIs.
 *
 * @return the EC2 service object to call AWS APIs.
 */// w w w. j a  v  a2  s . c o  m
private AmazonEC2 getEC2Service() {
    String aWSAccessId = serverConfig.getAWSAccessId();
    String aWSSecretKey = serverConfig.getAWSSecretKey();

    AmazonEC2 ec2Service;
    if (null != aWSAccessId && !"".equals(aWSAccessId) && null != aWSSecretKey && !"".equals(aWSSecretKey)) {
        ec2Service = new AmazonEC2Client(new BasicAWSCredentials(aWSAccessId, aWSSecretKey));
    } else {
        ec2Service = new AmazonEC2Client(new InstanceProfileCredentialsProvider());
    }

    String region = clientConfig.getRegion();
    region = region.trim().toLowerCase();
    ec2Service.setEndpoint("ec2." + region + ".amazonaws.com");
    return ec2Service;
}

From source file:com.netflix.eureka.util.AwsAsgUtil.java

License:Apache License

private Credentials initializeStsSession(String asgAccount) {
    AWSSecurityTokenService sts = new AWSSecurityTokenServiceClient(new InstanceProfileCredentialsProvider());
    String region = DiscoveryManager.getInstance().getEurekaClientConfig().getRegion();
    if (!region.equals("us-east-1")) {
        sts.setEndpoint("sts." + region + ".amazonaws.com");
    }/* w ww.  j a v  a  2s. c  om*/

    String roleName = EurekaServerConfigurationManager.getInstance().getConfiguration()
            .getListAutoScalingGroupsRoleName();

    String roleArn = "arn:aws:iam::" + asgAccount + ":role/" + roleName;

    AssumeRoleResult assumeRoleResult = sts.assumeRole(
            new AssumeRoleRequest().withRoleArn(roleArn).withRoleSessionName("sts-session-" + asgAccount));

    return assumeRoleResult.getCredentials();
}

From source file:com.netflix.eureka.util.AwsAsgUtil.java

License:Apache License

private static AmazonAutoScaling getAmazonAutoScalingClient() {
    String aWSAccessId = eurekaConfig.getAWSAccessId();
    String aWSSecretKey = eurekaConfig.getAWSSecretKey();
    ClientConfiguration clientConfiguration = new ClientConfiguration()
            .withConnectionTimeout(eurekaConfig.getASGQueryTimeoutMs());

    if (null != aWSAccessId && !"".equals(aWSAccessId) && null != aWSSecretKey && !"".equals(aWSSecretKey)) {
        return new AmazonAutoScalingClient(new BasicAWSCredentials(aWSAccessId, aWSSecretKey),
                clientConfiguration);/* ww  w  .  j  a  va2 s .c o  m*/
    } else {
        return new AmazonAutoScalingClient(new InstanceProfileCredentialsProvider(), clientConfiguration);
    }
}

From source file:com.netflix.eureka.util.EIPManager.java

License:Apache License

/**
 * Gets the EC2 service object to call AWS APIs.
 *
 * @return the EC2 service object to call AWS APIs.
 *//*w ww  .j  a va 2  s .  c  om*/
private AmazonEC2 getEC2Service() {
    eurekaConfig = EurekaServerConfigurationManager.getInstance().getConfiguration();

    String aWSAccessId = eurekaConfig.getAWSAccessId();
    String aWSSecretKey = eurekaConfig.getAWSSecretKey();

    AmazonEC2 ec2Service;
    if (null != aWSAccessId && !"".equals(aWSAccessId) && null != aWSSecretKey && !"".equals(aWSSecretKey)) {
        ec2Service = new AmazonEC2Client(new BasicAWSCredentials(aWSAccessId, aWSSecretKey));
    } else {
        ec2Service = new AmazonEC2Client(new InstanceProfileCredentialsProvider());
    }

    String region = DiscoveryManager.getInstance().getEurekaClientConfig().getRegion();
    region = region.trim().toLowerCase();
    ec2Service.setEndpoint("ec2." + region + ".amazonaws.com");
    return ec2Service;
}

From source file:com.nike.cerberus.module.CerberusModule.java

License:Apache License

private static <M extends AmazonWebServiceClient> M createAmazonClientInstance(Class<M> clientClass,
        Region region) {//from   w  w  w  .ja  va2 s  .  c  o m
    String cerberusRoleToAssume = System.getenv(CERBERUS_ASSUME_ROLE_ARN) != null
            ? System.getenv(CERBERUS_ASSUME_ROLE_ARN)
            : "";
    String cerberusRoleToAssumeExternalId = System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID) != null
            ? System.getenv(CERBERUS_ASSUME_ROLE_EXTERNAL_ID)
            : "";

    STSAssumeRoleSessionCredentialsProvider sTSAssumeRoleSessionCredentialsProvider = new STSAssumeRoleSessionCredentialsProvider.Builder(
            cerberusRoleToAssume, UUID.randomUUID().toString()).withExternalId(cerberusRoleToAssumeExternalId)
                    .build();

    AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(
            new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(),
            new ProfileCredentialsProvider(), sTSAssumeRoleSessionCredentialsProvider,
            new InstanceProfileCredentialsProvider());
    return region.createClient(clientClass, chain, new ClientConfiguration());
}

From source file:com.noctarius.hazelcast.aws.HazelcastAwsDiscoveryStrategy.java

License:Open Source License

private AWSCredentialsProvider buildCredentialsProvider() {
    String accessKey = getOrNull(AwsProperties.ACCESS_KEY);
    String secretKey = getOrNull(AwsProperties.SECRET_KEY);

    if (accessKey == null && secretKey == null) {
        return new AWSCredentialsProviderChain(new EnvironmentVariableCredentialsProvider(),
                new SystemPropertiesCredentialsProvider(), new InstanceProfileCredentialsProvider());
    }//from   w  w w .j  a  va 2s . c  om

    return new AWSCredentialsProviderChain(
            new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
}

From source file:edu.harvard.hms.dbmi.bd2k.irct.aws.event.result.S3AfterGetResult.java

License:Mozilla Public License

@Override
public void init(Map<String, String> parameters) {
    log = LogFactory.getLog("AWS S3 Monitoring");
    bucketName = parameters.get("Bucket Name");
    irctSaveLocation = parameters.get("resultDataFolder");
    s3Folder = parameters.get("s3Folder");

    s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider());

}

From source file:edu.harvard.hms.dbmi.bd2k.irct.aws.event.result.S3AfterSaveResult.java

License:Mozilla Public License

@Override
public void init(Map<String, String> parameters) {
    log = LogFactory.getLog("AWS S3 Monitoring");
    bucketName = parameters.get("Bucket Name");
    s3Folder = parameters.get("s3Folder");

    s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider());
}

From source file:edu.iit.credentials.Credentials.java

/**
 *
 * @return/*from  w w w .  ja  va2s  .c  o m*/
 */
public static AWSCredentials getCreds() {
    AWSCredentials credentials;
    try {
        credentials = new ProfileCredentialsProvider().getCredentials();
    } catch (Exception e) {
        credentials = new InstanceProfileCredentialsProvider().getCredentials();
    }

    return credentials;
}