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