use of com.amazonaws.services.ec2.AmazonEC2AsyncClientBuilder in project photon-model by vmware.
the class AWSUtils method getAsyncClient.
/**
* Method to get an EC2 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 #getEc2AsyncClient(AuthCredentialsServiceState, String,
* ExecutorService)}.
*
* @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 AmazonEC2AsyncClient getAsyncClient(AuthCredentialsServiceState credentials, String region, ExecutorService executorService) {
ClientConfiguration configuration = createClientConfiguration().withMaxConnections(100);
AmazonEC2AsyncClientBuilder ec2AsyncClientBuilder = AmazonEC2AsyncClientBuilder.standard().withClientConfiguration(configuration).withCredentials(getAwsStaticCredentialsProvider(credentials)).withExecutorFactory(() -> executorService);
if (region == null) {
region = Regions.DEFAULT_REGION.getName();
}
if (isAwsClientMock()) {
configuration.addHeader(AWS_REGION_HEADER, region);
ec2AsyncClientBuilder.setClientConfiguration(configuration);
AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(getAWSMockHost() + AWS_MOCK_EC2_ENDPOINT, region);
ec2AsyncClientBuilder.setEndpointConfiguration(endpointConfiguration);
} else {
ec2AsyncClientBuilder.setRegion(region);
}
return (AmazonEC2AsyncClient) ec2AsyncClientBuilder.build();
}
Aggregations