Search in sources :

Example 1 with AwsClientBuilder

use of com.amazonaws.client.builder.AwsClientBuilder in project iep by Netflix.

the class AwsClientFactory method newInstance.

/**
 * Create a new instance of an AWS client. This method will always create a new instance.
 * If you want to create or reuse an existing instance, then see
 * {@link #getInstance(String, Class, String)}.
 *
 * @param name
 *     Name of the client. This is used to load config settings specific to the name.
 * @param cls
 *     Class for the AWS client type to create, e.g. {@code AmazonEC2.class}.
 * @param accountId
 *     The AWS account id to use when assuming to a role. If null, then the account
 *     id should be specified directly in the role-arn setting or leave out the setting
 *     to use the default credentials provider.
 * @return
 *     AWS client instance.
 */
@SuppressWarnings("unchecked")
public <T> T newInstance(String name, Class<T> cls, String accountId) {
    try {
        final Class<?> clientCls = getClientClass(cls);
        Method builderMethod = clientCls.getMethod("builder");
        return (T) ((AwsClientBuilder) builderMethod.invoke(null)).withCredentials(createCredentialsProvider(name, accountId)).withClientConfiguration(createClientConfig(name)).withRegion(chooseRegion(name, cls)).build();
    } catch (Exception e) {
        throw new RuntimeException("failed to create instance of " + cls.getName(), e);
    }
}
Also used : AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) Method(java.lang.reflect.Method)

Example 2 with AwsClientBuilder

use of com.amazonaws.client.builder.AwsClientBuilder in project crate by crate.

the class S3Service method buildClient.

private AmazonS3 buildClient(final S3ClientSettings clientSettings) {
    final AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
    builder.withCredentials(buildCredentials(LOGGER, clientSettings));
    builder.withClientConfiguration(buildConfiguration(clientSettings));
    final String endpoint = Strings.hasLength(clientSettings.endpoint) ? clientSettings.endpoint : Constants.S3_HOSTNAME;
    LOGGER.debug("using endpoint [{}]", endpoint);
    // If the endpoint configuration isn't set on the builder then the default behaviour is to try
    // and work out what region we are in and use an appropriate endpoint - see AwsClientBuilder#setRegion.
    // In contrast, directly-constructed clients use s3.amazonaws.com unless otherwise instructed. We currently
    // use a directly-constructed client, and need to keep the existing behaviour to avoid a breaking change,
    // so to move to using the builder we must set it explicitly to keep the existing behaviour.
    // 
    // We do this because directly constructing the client is deprecated (was already deprecated in 1.1.223 too)
    // so this change removes that usage of a deprecated API.
    builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null));
    return builder.build();
}
Also used : AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder)

Aggregations

AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)2 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)1 Method (java.lang.reflect.Method)1