Search in sources :

Example 1 with AmazonKinesisClientBuilder

use of com.amazonaws.services.kinesis.AmazonKinesisClientBuilder in project flink by apache.

the class AWSUtil method createKinesisClient.

/**
 * Creates an Amazon Kinesis Client.
 *
 * @param configProps configuration properties containing the access key, secret key, and region
 * @param awsClientConfig preconfigured AWS SDK client configuration
 * @return a new Amazon Kinesis Client
 */
public static AmazonKinesis createKinesisClient(Properties configProps, ClientConfiguration awsClientConfig) {
    // set a Flink-specific user agent
    awsClientConfig.setUserAgentPrefix(AWSAsyncSinkUtil.formatFlinkUserAgentPrefix(KinesisDataStreamsConfigConstants.BASE_KINESIS_USER_AGENT_PREFIX_FORMAT));
    // utilize automatic refreshment of credentials by directly passing the
    // AWSCredentialsProvider
    AmazonKinesisClientBuilder builder = AmazonKinesisClientBuilder.standard().withCredentials(AWSUtil.getCredentialsProvider(configProps)).withClientConfiguration(awsClientConfig);
    if (configProps.containsKey(AWSConfigConstants.AWS_ENDPOINT)) {
        // If an endpoint is specified, we give preference to using an endpoint and use the
        // region property to
        // sign the request.
        builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(configProps.getProperty(AWSConfigConstants.AWS_ENDPOINT), configProps.getProperty(AWSConfigConstants.AWS_REGION)));
    } else {
        builder.withRegion(Regions.fromName(configProps.getProperty(AWSConfigConstants.AWS_REGION)));
    }
    return builder.build();
}
Also used : AmazonKinesisClientBuilder(com.amazonaws.services.kinesis.AmazonKinesisClientBuilder) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder)

Example 2 with AmazonKinesisClientBuilder

use of com.amazonaws.services.kinesis.AmazonKinesisClientBuilder in project beam by apache.

the class KinesisIOIT method createKinesisClient.

private static AmazonKinesis createKinesisClient() {
    AWSCredentials credentials = new BasicAWSCredentials(options.getAwsAccessKey(), options.getAwsSecretKey());
    AmazonKinesisClientBuilder clientBuilder = AmazonKinesisClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials));
    if (options.getAwsServiceEndpoint() != null) {
        clientBuilder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(options.getAwsServiceEndpoint(), options.getAwsKinesisRegion()));
    } else {
        clientBuilder.setRegion(options.getAwsKinesisRegion());
    }
    return clientBuilder.build();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonKinesisClientBuilder(com.amazonaws.services.kinesis.AmazonKinesisClientBuilder) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 3 with AmazonKinesisClientBuilder

use of com.amazonaws.services.kinesis.AmazonKinesisClientBuilder in project samza by apache.

the class KinesisSystemAdmin method createSystemStreamMetadata.

private SystemStreamMetadata createSystemStreamMetadata(String stream) {
    LOG.info("create stream metadata for stream {} based on aws stream", stream);
    Map<Partition, SystemStreamMetadata.SystemStreamPartitionMetadata> metadata = new HashMap<>();
    AmazonKinesisClient client = null;
    try {
        ClientConfiguration clientConfig = kConfig.getAWSClientConfig(system);
        AmazonKinesisClientBuilder builder = AmazonKinesisClientBuilder.standard().withCredentials(kConfig.credentialsProviderForStream(system, stream)).withClientConfiguration(clientConfig);
        builder.setRegion(kConfig.getRegion(system, stream).getName());
        client = (AmazonKinesisClient) builder.build();
        StreamDescription desc = client.describeStream(stream).getStreamDescription();
        IntStream.range(0, desc.getShards().size()).forEach(i -> metadata.put(new Partition(i), SYSTEM_STREAM_PARTITION_METADATA));
    } catch (Exception e) {
        String errMsg = "couldn't load metadata for stream " + stream;
        LOG.error(errMsg, e);
        throw new SamzaException(errMsg, e);
    } finally {
        if (client != null) {
            client.shutdown();
        }
    }
    return new SystemStreamMetadata(stream, metadata);
}
Also used : Partition(org.apache.samza.Partition) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) AmazonKinesisClient(com.amazonaws.services.kinesis.AmazonKinesisClient) HashMap(java.util.HashMap) StreamDescription(com.amazonaws.services.kinesis.model.StreamDescription) AmazonKinesisClientBuilder(com.amazonaws.services.kinesis.AmazonKinesisClientBuilder) SystemStreamMetadata(org.apache.samza.system.SystemStreamMetadata) SamzaException(org.apache.samza.SamzaException) ClientConfiguration(com.amazonaws.ClientConfiguration) SamzaException(org.apache.samza.SamzaException)

Aggregations

AmazonKinesisClientBuilder (com.amazonaws.services.kinesis.AmazonKinesisClientBuilder)3 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AmazonKinesisClient (com.amazonaws.services.kinesis.AmazonKinesisClient)1 StreamDescription (com.amazonaws.services.kinesis.model.StreamDescription)1 HashMap (java.util.HashMap)1 Partition (org.apache.samza.Partition)1 SamzaException (org.apache.samza.SamzaException)1 SystemStreamMetadata (org.apache.samza.system.SystemStreamMetadata)1 SystemStreamPartition (org.apache.samza.system.SystemStreamPartition)1