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:fi.yle.tools.aws.maven.AuthenticationInfoAWSCredentialsProviderChain.java

License:Apache License

AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
    super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(),
            new InstanceProfileCredentialsProvider(), new ProfileCredentialsProvider(),
            new AuthenticationInfoAWSCredentialsProvider(authenticationInfo));
}

From source file:gov.pnnl.cloud.KinesisApplication.java

License:Open Source License

private static void configure(String propertiesFile) throws IOException {

    if (propertiesFile != null) {
        loadProperties(propertiesFile);//w  ww. j  a  v  a  2 s.c  o  m
    }

    // ensure the JVM will refresh the cached IP values of AWS resources (e.g. service endpoints).
    java.security.Security.setProperty("networkaddress.cache.ttl", "60");

    String workerId = InetAddress.getLocalHost().getCanonicalHostName() + ":" + UUID.randomUUID();
    LOG.info("Using workerId: " + workerId);

    // Get credentials from IMDS. If unsuccessful, get them from the credential profiles file.
    AWSCredentialsProvider credentialsProvider = null;
    try {
        credentialsProvider = new InstanceProfileCredentialsProvider();
        // Verify we can fetch credentials from the provider
        credentialsProvider.getCredentials();
        LOG.info("Obtained credentials from the IMDS.");
    } catch (AmazonClientException e) {
        LOG.info("Unable to obtain credentials from the IMDS, trying classpath properties", e);
        credentialsProvider = new ProfileCredentialsProvider();
        // Verify we can fetch credentials from the provider
        credentialsProvider.getCredentials();
        LOG.info("Obtained credentials from the properties file.");
    }

    LOG.info("Using credentials with access key id: "
            + credentialsProvider.getCredentials().getAWSAccessKeyId());

    kinesisClientLibConfiguration = new KinesisClientLibConfiguration(applicationName, streamName,
            credentialsProvider, workerId).withInitialPositionInStream(initialPositionInStream)
                    .withRegionName(kinesisEndpoint);
}

From source file:hudson.plugins.ec2.EC2Cloud.java

License:Open Source License

public static AWSCredentialsProvider createCredentialsProvider(final boolean useInstanceProfileForCredentials,
        final String accessId, final Secret secretKey) {

    if (useInstanceProfileForCredentials) {
        return new InstanceProfileCredentialsProvider();
    }/*from  w w w  .  j a  va2s  . c  om*/

    BasicAWSCredentials credentials = new BasicAWSCredentials(accessId, Secret.toString(secretKey));
    return new StaticCredentialsProvider(credentials);
}

From source file:iit.edu.supadyay.s3.S3upload.java

public static List listOfObjects(String bucketname) {
    List objectNames = new ArrayList();
    //AmazonS3 s3client = new AmazonS3Client(getCredentials());
    AmazonS3 s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider());
    System.out.println("Listing keys now");
    for (S3ObjectSummary obj : s3client.listObjects(bucketname).getObjectSummaries()) {
        System.out.println(obj.getKey());
        objectNames.add(obj.getKey());//from  w  w  w  .j ava 2s  . c  om
    }
    //for (ObjectListing obj : s3client.listObjects(bucketname)){

    //}
    return objectNames;
}

From source file:iit.edu.supadyay.s3.S3upload.java

public static List listOfBuckets() {
    List bucketNames = new ArrayList();
    //AWSCredentials credentials = new BasicAWSCredentials(access, secret);
    //AmazonS3 s3client = new AmazonS3Client(getCredentials());
    AmazonS3 s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider());

    for (Bucket bucket : s3client.listBuckets()) {
        bucketNames.add(bucket.getName());
        s3client.listObjects(bucket.getName());
    }//ww  w. java  2s.c o m
    //bucketNames.addAll(s3client.listBuckets());
    bucketNames.toString();
    return bucketNames;
}

From source file:iit.edu.supadyay.s3.S3upload.java

public static boolean upload(String bucketName, String uploadFileName, String keyName)
        throws IOException, InterruptedException {

    //access = "AKIAJ2YSLRUZR5B3F5HQ";
    //secret = "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";
    //AWSCredentials credentials = new BasicAWSCredentials(access, secret);
    //AmazonS3 s3client = new AmazonS3Client(getCredentials());
    AmazonS3 s3client = new AmazonS3Client(new InstanceProfileCredentialsProvider());
    try {//from   w  ww .  j a  va2s  .  c  o m
        System.out.println("Uploading a new object to S3 from a file\n");
        File file = new File(uploadFileName);
        System.out.println("I am before here\n");
        s3client.createBucket(bucketName);
        System.out.println("I am here\n");

        s3client.putObject(new PutObjectRequest(bucketName, keyName, file));
        s3client.setObjectAcl(bucketName, keyName, CannedAccessControlList.PublicReadWrite);

    } catch (AmazonServiceException ase) {
        System.out.println("Caught an AmazonServiceException, which " + "means your request made it "
                + "to Amazon S3, but was rejected with an error response" + " for some reason.");
        System.out.println("Error Message:    " + ase.getMessage());
        System.out.println("HTTP Status Code: " + ase.getStatusCode());
        System.out.println("AWS Error Code:   " + ase.getErrorCode());
        System.out.println("Error Type:       " + ase.getErrorType());
        System.out.println("Request ID:       " + ase.getRequestId());
        return false;
    } catch (AmazonClientException ace) {
        System.out.println("Caught an AmazonClientException, which " + "means the client encountered "
                + "an internal error while trying to " + "communicate with S3, "
                + "such as not being able to access the network.");
        System.out.println("Error Message: " + ace.getMessage());
        return false;
    }
    return true;
}

From source file:io.druid.common.aws.AWSCredentialsUtils.java

License:Apache License

public static AWSCredentialsProviderChain defaultAWSCredentialsProviderChain(
        final AWSCredentialsConfig config) {
    return new AWSCredentialsProviderChain(new ConfigDrivenAwsCredentialsConfigProvider(config),
            new LazyFileSessionCredentialsProvider(config), new EnvironmentVariableCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(), new ProfileCredentialsProvider(),
            new InstanceProfileCredentialsProvider());
}

From source file:ohnosequences.ivy.S3Repository.java

License:Apache License

public S3Repository(String accessKey, String secretKey, boolean overwrite, Region region,
        CannedAccessControlList acl, boolean serverSideEncryption) {
    AWSCredentialsProvider provider = new InstanceProfileCredentialsProvider();
    try {//from w  ww .  java2s.  c o  m
        provider.getCredentials();
    } catch (AmazonClientException e1) {
        provider = new StaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey));
    }

    s3Client = new AmazonS3Client(provider);
    this.overwrite = overwrite;
    this.region = region;
    this.acl = acl;
    this.serverSideEncryption = serverSideEncryption;
}

From source file:org.adroitlogic.build.aws.maven.AuthenticationInfoAWSCredentialsProviderChain.java

License:Apache License

AuthenticationInfoAWSCredentialsProviderChain(AuthenticationInfo authenticationInfo) {
    super(new EnvironmentVariableCredentialsProvider(), new SystemPropertiesCredentialsProvider(),
            new InstanceProfileCredentialsProvider(),
            new AuthenticationInfoAWSCredentialsProvider(authenticationInfo));
}

From source file:org.apache.hadoop.dynamodb.DynamoDBClient.java

License:Open Source License

protected AWSCredentialsProvider getAWSCredentialsProvider(Configuration conf) {
    List<AWSCredentialsProvider> providersList = new ArrayList<>();

    // try to load custom credential provider, fail if a provider is specified but cannot be
    // initialized
    String providerClass = conf.get(DynamoDBConstants.CUSTOM_CREDENTIALS_PROVIDER_CONF);
    if (!Strings.isNullOrEmpty(providerClass)) {
        try {/*from  w ww. j  a v  a 2s. c om*/
            providersList.add(
                    (AWSCredentialsProvider) ReflectionUtils.newInstance(Class.forName(providerClass), conf));
        } catch (ClassNotFoundException e) {
            throw new RuntimeException("Custom AWSCredentialsProvider not found: " + providerClass, e);
        }
    }

    // try to fetch credentials from core-site
    String accessKey = conf.get(DYNAMODB_CREDENTIAL_PAIR_NAME.getAccessKeyName());
    String secretKey;
    if (Strings.isNullOrEmpty(accessKey)) {
        accessKey = conf.get(DEFAULT_CREDENTIAL_PAIR_NAME.getAccessKeyName());
        secretKey = conf.get(DEFAULT_CREDENTIAL_PAIR_NAME.getSecretKeyName());
    } else {
        secretKey = conf.get(DYNAMODB_CREDENTIAL_PAIR_NAME.getSecretKeyName());
    }

    if (Strings.isNullOrEmpty(accessKey) || Strings.isNullOrEmpty(secretKey)) {
        providersList.add(new InstanceProfileCredentialsProvider());
    } else {
        final AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        providersList.add(new AWSCredentialsProvider() {
            @Override
            public AWSCredentials getCredentials() {
                return credentials;
            }

            @Override
            public void refresh() {
            }
        });
    }

    AWSCredentialsProvider[] providerArray = providersList
            .toArray(new AWSCredentialsProvider[providersList.size()]);

    AWSCredentialsProviderChain providerChain = new AWSCredentialsProviderChain(providerArray);
    providerChain.setReuseLastProvider(true);
    return providerChain;
}