Example usage for com.amazonaws.auth EnvironmentVariableCredentialsProvider EnvironmentVariableCredentialsProvider

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

Introduction

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

Prototype

EnvironmentVariableCredentialsProvider

Source Link

Usage

From source file:com.gu.logback.appender.kinesis.helpers.CustomCredentialsProviderChain.java

License:Open Source License

public CustomCredentialsProviderChain() {
    super(new ClasspathPropertiesFileCredentialsProvider(), new InstanceProfileCredentialsProvider(),
            new SystemPropertiesCredentialsProvider(), new EnvironmentVariableCredentialsProvider());
}

From source file:com.handywedge.binarystore.store.aws.BinaryStoreManagerImpl.java

License:MIT License

/**
 * ?/*from  w  ww.j a v  a  2 s .c  o  m*/
 *
 * @param bucketName
 * @return s3client
 * @throws StoreException
 * @throws Exception
 */
private AmazonS3 getS3Client(String bucketName) throws StoreException {
    logger.debug("get S3 Client start.");
    // ?
    AWSCredentialsProvider provider = new EnvironmentVariableCredentialsProvider();

    // 
    ClientConfiguration clientConfig = new ClientConfiguration()

            // .withProtocol(Protocol.HTTPS) // Proxy
            // .withProxyHost("proxyHost")
            // .withProxyPort(80)
            // .withProxyUsername("proxyUsername")
            // .withProxyPassword("proxyPassword")

            .withConnectionTimeout(10000);

    // ?
    AmazonS3 s3client = AmazonS3ClientBuilder.standard().withCredentials(provider)
            .withClientConfiguration(clientConfig).withRegion(DEFAULT_REGION)
            .withForceGlobalBucketAccessEnabled(true).build();

    logger.debug("Region={}", s3client.getRegion());

    try {
        // ??
        if (!CommonUtils.isNullOrEmpty(bucketName) && !(s3client.doesBucketExistV2(bucketName))) {
            s3client.createBucket(new CreateBucketRequest(bucketName, DEFAULT_REGION.getName()));
        }
        // Get location.
        String bucketLocation = s3client.getBucketLocation(new GetBucketLocationRequest(bucketName));
        logger.info("bucket location={}", bucketLocation);
    } catch (AmazonClientException ace) {
        throw new StoreException(HttpStatus.SC_CONFLICT, ErrorClassification.BS0003, ace, "?");
    }

    logger.info("get S3 Client end.");
    return s3client;
}

From source file:com.importio.kinesis.elasticsearch.ElasticsearchExecutor.java

License:Open Source License

public ElasticsearchExecutor(Properties properties) {
    config = new KinesisConnectorConfiguration(properties, new EnvironmentVariableCredentialsProvider());
    initialize(config);/* w  w w.j ava2 s  .  co  m*/
}

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

License:Apache License

private static <M extends AmazonWebServiceClient> M createAmazonClientInstance(Class<M> clientClass,
        Region region) {//  w  ww  .  j a  v  a  2  s  . co 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());
    }// ww  w .ja va 2 s  .  c  om

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

From source file:com.sag.tn.storm.stormmaven.main.Main.java

License:Open Source License

public static void main(String[] args) {

    AWSCredentials credentials = null;/*from  w  w  w. j a v  a 2  s.  c om*/
    try {
        credentials = new EnvironmentVariableCredentialsProvider().getCredentials();
    } catch (Exception 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 (~/.aws/credentials), and is in valid format.", e);
    }

    AmazonSQS sqs = new AmazonSQSClient(credentials);

    sqs.purgeQueue(new PurgeQueueRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue"));

    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>10</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>11</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>12</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>13</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>14</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>15</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>16</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>17</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>18</Value></PurchaseOrderRequest>"));
    sqs.sendMessage(new SendMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue",
            "<PurchaseOrderRequest><Value>19</Value></PurchaseOrderRequest>"));

    System.out.println("sent");
    /*
    // Receive messages
    System.out.println("Receiving messages from MyQueue.\n");
    ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue");
            
    for(int i = 0; i < 7; i++) {
            
       List<Message> messages = sqs.receiveMessage(receiveMessageRequest).getMessages();
               
       System.out.println(messages.size());
               
       for (Message message : messages) {
       System.out.println("  Message");
       System.out.println("    MessageId:     " + message.getMessageId());
       System.out.println("    ReceiptHandle: " + message.getReceiptHandle());
       System.out.println("    MD5OfBody:     " + message.getMD5OfBody());
       System.out.println("    Body:          " + message.getBody());
       for (Entry<String, String> entry : message.getAttributes().entrySet()) {
           System.out.println("  Attribute");
           System.out.println("    Name:  " + entry.getKey());
           System.out.println("    Value: " + entry.getValue());
       }
               
       sqs.deleteMessage(new DeleteMessageRequest("https://sqs.us-west-2.amazonaws.com/238337343154/b2baaSTestQueue", message.getReceiptHandle()));
       }
    }*/

    /*MongoCredential credential = MongoCredential.createCredential("gergreg", "45345453", "34534fgalkej".toCharArray());
    MongoClient mClient = new MongoClient(new ServerAddress("rgergerg", 33760), Arrays.asList(credential));
    MongoDatabase db = mClient.getDatabase("5235235235");
    MongoCollection<Document> coll = db.getCollection("35235325235");*/

    /*MongoCursor<Document> cursor = coll.find(eq("rootTag", "IDataXMLCoder")).iterator();
    while(cursor.hasNext()) {
        Document document = cursor.next();
       System.out.println((String)document.get("docTypeId"));
       break;
    }*/

    /*coll.updateOne(eq("docTypeId", "f0cf1e95-9406-44dc-930f-8de9aae8ccaf123"),
        new Document("$inc", new Document("execs", 100)));
            
    System.out.println("updated...");
            
    mClient.close();*/

}

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: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:jp.classmethod.aws.gradle.AwsPluginExtension.java

License:Apache License

public AWSCredentialsProvider newCredentialsProvider(String profileName) {
    if (credentialsProvider != null) {
        return credentialsProvider;
    }/* w ww. j a  v a  2 s  .c  om*/
    String profileNameToUse = profileName != null ? profileName : this.profileName;
    if (Strings.isNullOrEmpty(profileNameToUse) == false) {
        List<AWSCredentialsProvider> providers = new ArrayList<AWSCredentialsProvider>();
        providers.add(new EnvironmentVariableCredentialsProvider());
        providers.add(new SystemPropertiesCredentialsProvider());
        providers.add(new ProfileCredentialsProvider(profileNameToUse));
        providers.add(new EC2ContainerCredentialsProviderWrapper());
        return new AWSCredentialsProviderChain(providers);
    }
    return DefaultAWSCredentialsProviderChain.getInstance();
}

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));
}