Example usage for com.amazonaws.services.s3 AmazonS3EncryptionClient encryptionBuilder

List of usage examples for com.amazonaws.services.s3 AmazonS3EncryptionClient encryptionBuilder

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3EncryptionClient encryptionBuilder.

Prototype

public static AmazonS3EncryptionClientBuilder encryptionBuilder() 

Source Link

Usage

From source file:io.prestosql.plugin.hive.s3.PrestoS3FileSystem.java

License:Apache License

private AmazonS3 createAmazonS3Client(Configuration hadoopConfig, ClientConfiguration clientConfig) {
    Optional<EncryptionMaterialsProvider> encryptionMaterialsProvider = createEncryptionMaterialsProvider(
            hadoopConfig);/*from   ww  w.  j  a  v a2s  .  co  m*/
    AmazonS3Builder<? extends AmazonS3Builder, ? extends AmazonS3> clientBuilder;

    String signerType = hadoopConfig.get(S3_SIGNER_TYPE);
    if (signerType != null) {
        clientConfig.withSignerOverride(signerType);
    }

    if (encryptionMaterialsProvider.isPresent()) {
        clientBuilder = AmazonS3EncryptionClient.encryptionBuilder().withCredentials(credentialsProvider)
                .withEncryptionMaterials(encryptionMaterialsProvider.get())
                .withClientConfiguration(clientConfig).withMetricsCollector(METRIC_COLLECTOR);
    } else {
        clientBuilder = AmazonS3Client.builder().withCredentials(credentialsProvider)
                .withClientConfiguration(clientConfig).withMetricsCollector(METRIC_COLLECTOR);
    }

    boolean regionOrEndpointSet = false;

    // use local region when running inside of EC2
    if (pinS3ClientToCurrentRegion) {
        Region region = Regions.getCurrentRegion();
        if (region != null) {
            clientBuilder = clientBuilder.withRegion(region.getName());
            regionOrEndpointSet = true;
        }
    }

    String endpoint = hadoopConfig.get(S3_ENDPOINT);
    if (endpoint != null) {
        clientBuilder = clientBuilder.withEndpointConfiguration(new EndpointConfiguration(endpoint, null));
        regionOrEndpointSet = true;
    }

    if (isPathStyleAccess) {
        clientBuilder = clientBuilder.enablePathStyleAccess();
    }

    if (!regionOrEndpointSet) {
        clientBuilder = clientBuilder.withRegion(US_EAST_1);
        clientBuilder.setForceGlobalBucketAccessEnabled(true);
    }

    return clientBuilder.build();
}