use of com.amazonaws.services.cloudwatch.AmazonCloudWatchAsyncClientBuilder in project photon-model by vmware.
the class AWSUtils method getStatsAsyncClient.
/**
* Method to get a CloudWatch Async Client.
*
* Note: ARN-based credentials will not work unless they have already been exchanged to
* AWS for session credentials. If unset, this method will fail. To enable ARN-based
* credentials, migrate to {@link #getCloudWatchStatsAsyncClient(AuthCredentialsServiceState,
* String, ExecutorService, boolean)}.
*
* @param credentials An {@link AuthCredentialsServiceState} object.
* @param region The region to get the AWS client in.
* @param executorService The executor service to run async services in.
*/
public static AmazonCloudWatchAsyncClient getStatsAsyncClient(AuthCredentialsServiceState credentials, String region, ExecutorService executorService, boolean isMockRequest) {
ClientConfiguration configuration = createClientConfiguration();
AmazonCloudWatchAsyncClientBuilder amazonCloudWatchAsyncClientBuilder = AmazonCloudWatchAsyncClientBuilder.standard().withClientConfiguration(configuration).withCredentials(getAwsStaticCredentialsProvider(credentials)).withExecutorFactory(() -> executorService);
if (region == null) {
region = Regions.DEFAULT_REGION.getName();
}
if (isAwsClientMock()) {
configuration.addHeader(AWS_REGION_HEADER, region);
amazonCloudWatchAsyncClientBuilder.setClientConfiguration(configuration);
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(getAWSMockHost() + AWS_MOCK_CLOUDWATCH_ENDPOINT, region);
amazonCloudWatchAsyncClientBuilder.setEndpointConfiguration(endpointConfiguration);
} else {
amazonCloudWatchAsyncClientBuilder.setRegion(region);
}
return (AmazonCloudWatchAsyncClient) amazonCloudWatchAsyncClientBuilder.build();
}
Aggregations