Example usage for com.amazonaws.auth DefaultAWSCredentialsProviderChain getInstance

List of usage examples for com.amazonaws.auth DefaultAWSCredentialsProviderChain getInstance

Introduction

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

Prototype

public static DefaultAWSCredentialsProviderChain getInstance() 

Source Link

Usage

From source file:com.netflix.metacat.main.configs.SNSNotificationsConfig.java

License:Apache License

/**
 * If SNS notifications are desired and no existing client has been created elsewhere
 * in the application create a default client here.
 *
 * @return The configured SNS client//from ww  w.  j av a2 s  . c o m
 */
//TODO: See what spring-cloud-aws would provide automatically...
@Bean
@ConditionalOnMissingBean(AmazonSNS.class)
public AmazonSNS amazonSNS() {
    return new AmazonSNSClient(DefaultAWSCredentialsProviderChain.getInstance());
}

From source file:com.netflix.spinnaker.halyard.config.validate.v1.providers.aws.AwsAccountValidator.java

License:Apache License

public static AWSCredentialsProvider getAwsCredentialsProvider(String accessKeyId, String secretKey) {
    if (accessKeyId != null && secretKey != null) {
        return new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKeyId, secretKey));
    } else {/*from   w  w w. j  a  v a  2  s .  c  o  m*/
        return DefaultAWSCredentialsProviderChain.getInstance();
    }
}

From source file:com.nike.cerberus.lambda.waf.AthenaQuery.java

License:Apache License

/**
 * Executes an Athena query and waits for it to finish returning the results
 *//*from   w  ww  . j av  a2s . com*/
private GetQueryResultsResult executeAthenaQuery(String query) throws InterruptedException {

    logger.info("QUERY: " + query);

    AmazonAthena athena = AmazonAthenaClient.builder().withRegion(Regions.US_WEST_2)
            .withCredentials(DefaultAWSCredentialsProviderChain.getInstance()).build();

    StartQueryExecutionResult result = athena.startQueryExecution(new StartQueryExecutionRequest()
            .withQueryString(query).withResultConfiguration(new ResultConfiguration().withOutputLocation(
                    "s3://aws-athena-query-results-933764306573-us-west-2/ip-address-translator")));

    String id = result.getQueryExecutionId();

    String state;
    do {
        state = athena.getQueryExecution(new GetQueryExecutionRequest().withQueryExecutionId(id))
                .getQueryExecution().getStatus().getState();
        logger.info(String.format("Polling for query to finish: current status: %s", state));
        Thread.sleep(1000);
    } while (state.equals("RUNNING"));

    logger.info(String.format("The query: %s is in state: %s, fetching results", id, state));

    return athena.getQueryResults(new GetQueryResultsRequest().withQueryExecutionId(id));
}

From source file:jp.classmethod.aws.gradle.AwsPluginExtension.java

License:Apache License

public AWSCredentialsProvider newCredentialsProvider(String profileName) {
    if (credentialsProvider != null) {
        return credentialsProvider;
    }/*from w w  w  .  j a  va 2  s.  c  o m*/
    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.apache.bookkeeper.mledger.offload.jcloud.impl.BlobStoreManagedLedgerOffloader.java

License:Apache License

public static Credentials getCredentials(String driver, TieredStorageConfigurationData conf)
        throws IOException {
    // credentials:
    //   for s3, get by DefaultAWSCredentialsProviderChain.
    //   for gcs, use downloaded file 'google_creds.json', which contains service account key by
    //     following instructions in page https://support.google.com/googleapi/answer/6158849

    if (isGcsDriver(driver)) {
        String gcsKeyPath = conf.getGcsManagedLedgerOffloadServiceAccountKeyFile();
        if (Strings.isNullOrEmpty(gcsKeyPath)) {
            throw new IOException("The service account key path is empty for GCS driver");
        }/*from  w w  w  .j  a v  a  2  s . c om*/
        try {
            String gcsKeyContent = Files.toString(new File(gcsKeyPath), Charset.defaultCharset());
            return new GoogleCredentialsFromJson(gcsKeyContent).get();
        } catch (IOException ioe) {
            log.error("Cannot read GCS service account credentials file: {}", gcsKeyPath);
            throw new IOException(ioe);
        }
    } else if (isS3Driver(driver)) {
        AWSCredentials credentials = null;
        try {
            DefaultAWSCredentialsProviderChain creds = DefaultAWSCredentialsProviderChain.getInstance();
            credentials = creds.getCredentials();
        } catch (Exception e) {
            // allowed, some mock s3 service not need credential
            log.warn("Exception when get credentials for s3 ", e);
        }

        String id = "accesskey";
        String key = "secretkey";
        if (credentials != null) {
            id = credentials.getAWSAccessKeyId();
            key = credentials.getAWSSecretKey();
        }
        return new Credentials(id, key);
    } else {
        throw new IOException("Not support this kind of driver: " + driver);
    }
}

From source file:org.apache.metamodel.dynamodb.DynamoDbDataContextFactory.java

License:Apache License

private AWSCredentialsProvider getCredentials(DataContextProperties properties) {
    if (properties.getUsername() != null) {
        final BasicAWSCredentials credentials = new BasicAWSCredentials(properties.getUsername(),
                properties.getPassword());
        return new AWSStaticCredentialsProvider(credentials);
    } else {//  w w  w  . j  ava  2  s.  c o  m
        return DefaultAWSCredentialsProviderChain.getInstance();
    }
}

From source file:org.datacleaner.connection.DynamoDbDatastore.java

License:Open Source License

@Override
protected UsageAwareDatastoreConnection<DynamoDbDataContext> createDatastoreConnection() {
    final AmazonDynamoDBClientBuilder clientBuilder = AmazonDynamoDBClientBuilder.standard();
    if (!Strings.isNullOrEmpty(_region)) {
        clientBuilder.setRegion(_region);
    }/*from   ww w.j  a  va  2s . c o  m*/
    final AWSCredentialsProvider credentialsProvider;
    if (!Strings.isNullOrEmpty(_accessKeyId)) {
        credentialsProvider = new AWSStaticCredentialsProvider(
                new BasicAWSCredentials(_accessKeyId, _secretAccessKey));
    } else {
        credentialsProvider = DefaultAWSCredentialsProviderChain.getInstance();
    }
    clientBuilder.setCredentials(credentialsProvider);
    final AmazonDynamoDB client = clientBuilder.build();
    final DynamoDbDataContext dataContext = new DynamoDbDataContext(client, _tableDefs);
    return new UpdateableDatastoreConnectionImpl<>(dataContext, this);
}

From source file:org.pentaho.amazon.s3.S3CredentialsProvider.java

License:Apache License

public static AWSCredentials getAWSCredentials() {
    return DefaultAWSCredentialsProviderChain.getInstance().getCredentials();
}

From source file:org.pentaho.hadoop.shim.common.format.S3NCredentialUtils.java

License:Apache License

public static void applyS3CredentialsToHadoopConfigurationIfNecessary(String filename, Configuration conf) {
    Path outputFile = new Path(scrubFilePathIfNecessary(filename));
    URI uri = outputFile.toUri();
    String scheme = uri != null ? uri.getScheme() : null;
    if (scheme != null && scheme.equals(S3NSCHEME)) {
        AWSCredentials credentials = DefaultAWSCredentialsProviderChain.getInstance().getCredentials();
        conf.set("fs.s3n.awsAccessKeyId", credentials.getAWSAccessKeyId());
        conf.set("fs.s3n.awsSecretAccessKey", credentials.getAWSSecretKey());
        conf.set("fs.s3.buffer.dir", System.getProperty("java.io.tmpdir"));
    }/*from w w w  .  j a v a  2  s.c  om*/
}

From source file:tech.greenfield.aws.Tools.java

License:Open Source License

public static AWSCredentialsProvider getCredsProvider() {
    String forceProfile = System.getenv("AWS_PROFILE");
    if (Objects.nonNull(forceProfile) && !forceProfile.isEmpty())
        return new ProfileCredentialsProvider(forceProfile);
    return DefaultAWSCredentialsProviderChain.getInstance();
}