Example usage for com.amazonaws.auth DefaultAWSCredentialsProviderChain DefaultAWSCredentialsProviderChain

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

Introduction

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

Prototype

public DefaultAWSCredentialsProviderChain() 

Source Link

Usage

From source file:org.apache.apex.malhar.contrib.kinesis.KinesisOperatorTestBase.java

License:Apache License

private void createClient() {
    credentials = new DefaultAWSCredentialsProviderChain();
    client = new AmazonKinesisClient(credentials);
}

From source file:org.apache.beam.sdk.io.kinesis.TalendKinesisProvider.java

License:Open Source License

@Override
public AmazonKinesis get() {
    AWSCredentialsProviderChain credentials = null;
    if (specifyCredentials) {
        credentials = new AWSCredentialsProviderChain(new BasicAWSCredentialsProvider(accessKey, secretKey),
                new DefaultAWSCredentialsProviderChain(), new AnonymousAWSCredentialsProvider());
    } else {//from ww  w .  j  a v a 2  s  .  c  om
        // do not be polluted by hidden accessKey/secretKey
        credentials = new AWSCredentialsProviderChain(new DefaultAWSCredentialsProviderChain(),
                new AnonymousAWSCredentialsProvider());
    }
    if (specifySTS) {
        STSAssumeRoleSessionCredentialsProvider.Builder builder = new STSAssumeRoleSessionCredentialsProvider.Builder(
                roleArn, roleSessionName).withLongLivedCredentialsProvider(credentials);
        if (specifyRoleExternalId) {
            builder = builder.withExternalId(roleExternalId);
        }
        if (specifySTSEndpoint) {
            builder = builder.withServiceEndpoint(stsEndpoint);
        }
        credentials = new AWSCredentialsProviderChain(builder.build());
    }
    AmazonKinesisClient client = new AmazonKinesisClient(credentials);
    client.withRegion(region);
    if (specifyEndpoint) {
        client.setEndpoint(endpoint);
    }
    return client;
}

From source file:org.apache.flink.streaming.connectors.kinesis.util.AWSUtil.java

License:Apache License

/**
 * Return a {@link AWSCredentialsProvider} instance corresponding to the configuration properties.
 *
 * @param configProps the configuration properties
 * @return The corresponding AWS Credentials Provider instance
 *///from  w w  w .  ja  va 2  s  .  co  m
public static AWSCredentialsProvider getCredentialsProvider(final Properties configProps) {
    CredentialProvider credentialProviderType;
    if (!configProps.containsKey(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER)) {
        if (configProps.containsKey(AWSConfigConstants.AWS_ACCESS_KEY_ID)
                && configProps.containsKey(AWSConfigConstants.AWS_SECRET_ACCESS_KEY)) {
            // if the credential provider type is not specified, but the Access Key ID and Secret Key are given, it will default to BASIC
            credentialProviderType = CredentialProvider.BASIC;
        } else {
            // if the credential provider type is not specified, it will default to AUTO
            credentialProviderType = CredentialProvider.AUTO;
        }
    } else {
        credentialProviderType = CredentialProvider
                .valueOf(configProps.getProperty(AWSConfigConstants.AWS_CREDENTIALS_PROVIDER));
    }

    AWSCredentialsProvider credentialsProvider;

    switch (credentialProviderType) {
    case ENV_VAR:
        credentialsProvider = new EnvironmentVariableCredentialsProvider();
        break;
    case SYS_PROP:
        credentialsProvider = new SystemPropertiesCredentialsProvider();
        break;
    case PROFILE:
        String profileName = configProps.getProperty(AWSConfigConstants.AWS_PROFILE_NAME, null);
        String profileConfigPath = configProps.getProperty(AWSConfigConstants.AWS_PROFILE_PATH, null);
        credentialsProvider = (profileConfigPath == null) ? new ProfileCredentialsProvider(profileName)
                : new ProfileCredentialsProvider(profileConfigPath, profileName);
        break;
    case BASIC:
        credentialsProvider = new AWSCredentialsProvider() {
            @Override
            public AWSCredentials getCredentials() {
                return new BasicAWSCredentials(configProps.getProperty(AWSConfigConstants.AWS_ACCESS_KEY_ID),
                        configProps.getProperty(AWSConfigConstants.AWS_SECRET_ACCESS_KEY));
            }

            @Override
            public void refresh() {
                // do nothing
            }
        };
        break;
    default:
    case AUTO:
        credentialsProvider = new DefaultAWSCredentialsProviderChain();
    }

    return credentialsProvider;
}

From source file:org.apache.nifi.processors.aws.credentials.provider.factory.strategies.ExplicitDefaultCredentialsStrategy.java

License:Apache License

@Override
public AWSCredentialsProvider getCredentialsProvider(Map<PropertyDescriptor, String> properties) {
    return new DefaultAWSCredentialsProviderChain();
}

From source file:org.apache.samza.system.kinesis.KinesisConfig.java

License:Apache License

/**
 * Get the appropriate CredentialProvider for a given system stream.
 * @param system name of the system/*from w ww  .  ja v a2s .  c  o  m*/
 * @param stream name of the stream
 * @return AWSCredentialsProvider
 */
AWSCredentialsProvider credentialsProviderForStream(String system, String stream) {
    // Try to load credentials in the following order:
    // 1. Access key from the config and passed in secretKey
    // 2. From the default credential provider chain (environment variables, system properties, AWS profile file, etc)
    return new AWSCredentialsProviderChain(new KinesisAWSCredentialsProvider(getStreamAccessKey(system, stream),
            getStreamSecretKey(system, stream)), new DefaultAWSCredentialsProviderChain());
}

From source file:org.apache.spark.examples.streaming.JavaKinesisWordCountASL.java

License:Apache License

public static void main(String[] args) throws Exception {
    // Check that all required args were passed in.
    if (args.length != 3) {
        System.err.println("Usage: JavaKinesisWordCountASL <stream-name> <endpoint-url>\n\n"
                + "    <app-name> is the name of the app, used to track the read data in DynamoDB\n"
                + "    <stream-name> is the name of the Kinesis stream\n"
                + "    <endpoint-url> is the endpoint of the Kinesis service\n"
                + "                   (e.g. https://kinesis.us-east-1.amazonaws.com)\n"
                + "Generate data for the Kinesis stream using the example KinesisWordProducerASL.\n"
                + "See http://spark.apache.org/docs/latest/streaming-kinesis-integration.html for more\n"
                + "details.\n");
        System.exit(1);// ww w  .j a  v a2 s.  c om
    }

    // Set default log4j logging level to WARN to hide Spark logs
    StreamingExamples.setStreamingLogLevels();

    // Populate the appropriate variables from the given args
    String kinesisAppName = args[0];
    String streamName = args[1];
    String endpointUrl = args[2];

    // Create a Kinesis client in order to determine the number of shards for the given stream
    AmazonKinesisClient kinesisClient = new AmazonKinesisClient(new DefaultAWSCredentialsProviderChain());
    kinesisClient.setEndpoint(endpointUrl);
    int numShards = kinesisClient.describeStream(streamName).getStreamDescription().getShards().size();

    // In this example, we're going to create 1 Kinesis Receiver/input DStream for each shard.
    // This is not a necessity; if there are less receivers/DStreams than the number of shards,
    // then the shards will be automatically distributed among the receivers and each receiver
    // will receive data from multiple shards.
    int numStreams = numShards;

    // Spark Streaming batch interval
    Duration batchInterval = new Duration(2000);

    // Kinesis checkpoint interval.  Same as batchInterval for this example.
    Duration kinesisCheckpointInterval = batchInterval;

    // Get the region name from the endpoint URL to save Kinesis Client Library metadata in
    // DynamoDB of the same region as the Kinesis stream
    String regionName = KinesisExampleUtils.getRegionNameByEndpoint(endpointUrl);

    // Setup the Spark config and StreamingContext
    SparkConf sparkConfig = new SparkConf().setAppName("JavaKinesisWordCountASL");
    JavaStreamingContext jssc = new JavaStreamingContext(sparkConfig, batchInterval);

    // Create the Kinesis DStreams
    List<JavaDStream<byte[]>> streamsList = new ArrayList<>(numStreams);
    for (int i = 0; i < numStreams; i++) {
        streamsList.add(KinesisUtils.createStream(jssc, kinesisAppName, streamName, endpointUrl, regionName,
                InitialPositionInStream.LATEST, kinesisCheckpointInterval, StorageLevel.MEMORY_AND_DISK_2()));
    }

    // Union all the streams if there is more than 1 stream
    JavaDStream<byte[]> unionStreams;
    if (streamsList.size() > 1) {
        unionStreams = jssc.union(streamsList.get(0), streamsList.subList(1, streamsList.size()));
    } else {
        // Otherwise, just use the 1 stream
        unionStreams = streamsList.get(0);
    }

    // Convert each line of Array[Byte] to String, and split into words
    JavaDStream<String> words = unionStreams.flatMap(new FlatMapFunction<byte[], String>() {
        @Override
        public Iterator<String> call(byte[] line) {
            String s = new String(line, StandardCharsets.UTF_8);
            return Arrays.asList(WORD_SEPARATOR.split(s)).iterator();
        }
    });

    // Map each word to a (word, 1) tuple so we can reduce by key to count the words
    JavaPairDStream<String, Integer> wordCounts = words.mapToPair(new PairFunction<String, String, Integer>() {
        @Override
        public Tuple2<String, Integer> call(String s) {
            return new Tuple2<>(s, 1);
        }
    }).reduceByKey(new Function2<Integer, Integer, Integer>() {
        @Override
        public Integer call(Integer i1, Integer i2) {
            return i1 + i2;
        }
    });

    // Print the first 10 wordCounts
    wordCounts.print();

    // Start the streaming context and await termination
    jssc.start();
    jssc.awaitTermination();
}

From source file:org.apache.storm.s3.output.UploaderFactory.java

License:Apache License

public static Uploader buildUploader(Map conf) {
    Protocol protocol = Protocol.HTTPS;//from   w w  w  .  j av  a 2s  . c  o  m
    String proxy = null;
    int proxyPort = 0;
    if (conf.containsKey(S3_PROTOCOL)) {
        protocol = Protocol.valueOf((String) conf.get(S3_PROTOCOL));
    }
    if (conf.containsKey(S3_PROXY)) {
        proxy = (String) conf.get(S3_PROXY);
    }
    if (conf.containsKey(S3_PROXY_PORT)) {
        proxyPort = ((Long) conf.get(S3_PROXY_PORT)).intValue();
    }
    AWSCredentialsProvider provider = new DefaultAWSCredentialsProviderChain();
    AWSCredentials credentials = provider.getCredentials();
    ClientConfiguration config = new ClientConfiguration().withProtocol(protocol);
    if (proxy != null) {
        config.withProxyHost(proxy);
    }
    if (proxyPort != 0) {
        config.withProxyPort(proxyPort);
    }
    AmazonS3 client = new AmazonS3Client(credentials, config);
    if (conf.containsKey(S3_ENDPOINT)) {
        client.setEndpoint((String) conf.get(S3_ENDPOINT));
    }
    return getUploader(conf, client);
}

From source file:org.apache.usergrid.chop.api.store.amazon.AmazonUtils.java

License:Apache License

/**
 * @param accessKey// w w  w.j av a2s. c o m
 * @param secretKey
 * @return
 */
public static AmazonEC2Client getEC2Client(String accessKey, String secretKey) {
    AWSCredentialsProvider provider;
    if (accessKey != null && secretKey != null) {
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
        provider = new StaticCredentialsProvider(credentials);
    } else {
        provider = new DefaultAWSCredentialsProviderChain();
    }

    AmazonEC2Client client = new AmazonEC2Client(provider);

    ClientConfiguration configuration = new ClientConfiguration();
    configuration.setProtocol(Protocol.HTTPS);
    client.setConfiguration(configuration);
    return client;
}

From source file:org.apache.zeppelin.notebook.repo.OldS3NotebookRepo.java

License:Apache License

public void init(ZeppelinConfiguration conf) throws IOException {
    this.conf = conf;
    bucketName = conf.getS3BucketName();
    user = conf.getS3User();//  w  ww. jav  a  2  s  . c om
    useServerSideEncryption = conf.isS3ServerSideEncryption();

    // always use the default provider chain
    AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
    CryptoConfiguration cryptoConf = new CryptoConfiguration();
    String keyRegion = conf.getS3KMSKeyRegion();

    if (StringUtils.isNotBlank(keyRegion)) {
        cryptoConf.setAwsKmsRegion(Region.getRegion(Regions.fromName(keyRegion)));
    }

    ClientConfiguration cliConf = createClientConfiguration();

    // see if we should be encrypting data in S3
    String kmsKeyID = conf.getS3KMSKeyID();
    if (kmsKeyID != null) {
        // use the AWS KMS to encrypt data
        KMSEncryptionMaterialsProvider emp = new KMSEncryptionMaterialsProvider(kmsKeyID);
        this.s3client = new AmazonS3EncryptionClient(credentialsProvider, emp, cliConf, cryptoConf);
    } else if (conf.getS3EncryptionMaterialsProviderClass() != null) {
        // use a custom encryption materials provider class
        EncryptionMaterialsProvider emp = createCustomProvider(conf);
        this.s3client = new AmazonS3EncryptionClient(credentialsProvider, emp, cliConf, cryptoConf);
    } else {
        // regular S3
        this.s3client = new AmazonS3Client(credentialsProvider, cliConf);
    }

    // set S3 endpoint to use
    s3client.setEndpoint(conf.getS3Endpoint());
}

From source file:org.apache.zeppelin.notebook.repo.S3NotebookRepo.java

License:Apache License

public void init(ZeppelinConfiguration conf) throws IOException {
    this.conf = conf;
    bucketName = conf.getS3BucketName();
    user = conf.getS3User();//from   www.  ja v a  2  s.  c  om
    rootFolder = user + "/notebook";
    useServerSideEncryption = conf.isS3ServerSideEncryption();

    // always use the default provider chain
    AWSCredentialsProvider credentialsProvider = new DefaultAWSCredentialsProviderChain();
    CryptoConfiguration cryptoConf = new CryptoConfiguration();
    String keyRegion = conf.getS3KMSKeyRegion();

    if (StringUtils.isNotBlank(keyRegion)) {
        cryptoConf.setAwsKmsRegion(Region.getRegion(Regions.fromName(keyRegion)));
    }

    ClientConfiguration cliConf = createClientConfiguration();

    // see if we should be encrypting data in S3
    String kmsKeyID = conf.getS3KMSKeyID();
    if (kmsKeyID != null) {
        // use the AWS KMS to encrypt data
        KMSEncryptionMaterialsProvider emp = new KMSEncryptionMaterialsProvider(kmsKeyID);
        this.s3client = new AmazonS3EncryptionClient(credentialsProvider, emp, cliConf, cryptoConf);
    } else if (conf.getS3EncryptionMaterialsProviderClass() != null) {
        // use a custom encryption materials provider class
        EncryptionMaterialsProvider emp = createCustomProvider(conf);
        this.s3client = new AmazonS3EncryptionClient(credentialsProvider, emp, cliConf, cryptoConf);
    } else {
        // regular S3
        this.s3client = new AmazonS3Client(credentialsProvider, cliConf);
    }

    // set S3 endpoint to use
    s3client.setEndpoint(conf.getS3Endpoint());
}