Search in sources :

Example 11 with EndpointConfiguration

use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project presto by prestodb.

the class PrestoS3ClientFactory method getS3Client.

synchronized AmazonS3 getS3Client(Configuration config, HiveClientConfig clientConfig) {
    if (s3Client != null) {
        return s3Client;
    }
    HiveS3Config defaults = new HiveS3Config();
    String userAgentPrefix = config.get(S3_USER_AGENT_PREFIX, defaults.getS3UserAgentPrefix());
    int maxErrorRetries = config.getInt(S3_MAX_ERROR_RETRIES, defaults.getS3MaxErrorRetries());
    boolean sslEnabled = config.getBoolean(S3_SSL_ENABLED, defaults.isS3SslEnabled());
    Duration connectTimeout = Duration.valueOf(config.get(S3_CONNECT_TIMEOUT, defaults.getS3ConnectTimeout().toString()));
    Duration socketTimeout = Duration.valueOf(config.get(S3_SOCKET_TIMEOUT, defaults.getS3SocketTimeout().toString()));
    int maxConnections = config.getInt(S3_SELECT_PUSHDOWN_MAX_CONNECTIONS, clientConfig.getS3SelectPushdownMaxConnections());
    if (clientConfig.isS3SelectPushdownEnabled()) {
        s3UserAgentSuffix = "presto-select";
    }
    ClientConfiguration clientConfiguration = new ClientConfiguration().withMaxErrorRetry(maxErrorRetries).withProtocol(sslEnabled ? Protocol.HTTPS : Protocol.HTTP).withConnectionTimeout(toIntExact(connectTimeout.toMillis())).withSocketTimeout(toIntExact(socketTimeout.toMillis())).withMaxConnections(maxConnections).withUserAgentPrefix(userAgentPrefix).withUserAgentSuffix(s3UserAgentSuffix);
    AWSCredentialsProvider awsCredentialsProvider = getAwsCredentialsProvider(config, defaults);
    AmazonS3Builder<? extends AmazonS3Builder, ? extends AmazonS3> clientBuilder = AmazonS3Client.builder().withCredentials(awsCredentialsProvider).withClientConfiguration(clientConfiguration).withMetricsCollector(new PrestoS3FileSystemMetricCollector(PrestoS3FileSystem.getFileSystemStats())).enablePathStyleAccess();
    boolean regionOrEndpointSet = false;
    String endpoint = config.get(S3_ENDPOINT);
    boolean pinS3ClientToCurrentRegion = config.getBoolean(S3_PIN_CLIENT_TO_CURRENT_REGION, defaults.isPinS3ClientToCurrentRegion());
    verify(!pinS3ClientToCurrentRegion || endpoint == null, "Invalid configuration: either endpoint can be set or S3 client can be pinned to the current region");
    // use local region when running inside of EC2
    if (pinS3ClientToCurrentRegion) {
        Region region = Regions.getCurrentRegion();
        if (region != null) {
            clientBuilder.withRegion(region.getName());
            regionOrEndpointSet = true;
        }
    }
    if (!isNullOrEmpty(endpoint)) {
        clientBuilder.withEndpointConfiguration(new EndpointConfiguration(endpoint, null));
        regionOrEndpointSet = true;
    }
    if (!regionOrEndpointSet) {
        clientBuilder.withRegion(US_EAST_1);
        clientBuilder.setForceGlobalBucketAccessEnabled(true);
    }
    s3Client = clientBuilder.build();
    return s3Client;
}
Also used : Region(com.amazonaws.regions.Region) Duration(io.airlift.units.Duration) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider)

Example 12 with EndpointConfiguration

use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project presto by prestodb.

the class PrestoS3FileSystem method createAmazonS3Client.

private AmazonS3 createAmazonS3Client(Configuration hadoopConfig, ClientConfiguration clientConfig) {
    Optional<EncryptionMaterialsProvider> encryptionMaterialsProvider = createEncryptionMaterialsProvider(hadoopConfig);
    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();
}
Also used : EncryptionMaterialsProvider(com.amazonaws.services.s3.model.EncryptionMaterialsProvider) KMSEncryptionMaterialsProvider(com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider) Region(com.amazonaws.regions.Region) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)

Example 13 with EndpointConfiguration

use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project OsmAnd-tools by osmandapp.

the class StorageService method getStorageProviderById.

private StorageType getStorageProviderById(String id) {
    id = id.trim();
    StorageType st = storageProviders.get(id);
    if (st != null) {
        return st;
    }
    if (id.equals(LOCAL_STORAGE)) {
        st = new StorageType();
        st.local = true;
    } else {
        String prefix = "storage.datasource." + id + ".";
        String endpointUrl = env.getProperty(prefix + "endpoint");
        checkNotNull(endpointUrl, "endpoint", id);
        String region = env.getProperty(prefix + "region");
        checkNotNull(region, "endpoint", id);
        String bucket = env.getProperty(prefix + "bucket");
        checkNotNull(region, "bucket", id);
        String accessKey = env.getProperty(prefix + "accesskey");
        String secretKey = env.getProperty(prefix + "secretkey");
        AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withEndpointConfiguration(new EndpointConfiguration(endpointUrl, region));
        if (!Algorithms.isEmpty(accessKey)) {
            builder = builder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)));
        }
        AmazonS3 s3 = builder.build();
        st = new StorageType();
        st.bucket = bucket;
        st.s3Conn = s3;
    }
    storageProviders.put(id, st);
    return st;
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)13 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)6 ClientConfiguration (com.amazonaws.ClientConfiguration)5 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)5 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)4 Region (com.amazonaws.regions.Region)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)3 ClientConfigurationFactory (com.amazonaws.ClientConfigurationFactory)2 AWSCredentialsProvider (com.amazonaws.auth.AWSCredentialsProvider)2 DefaultAwsRegionProviderChain (com.amazonaws.regions.DefaultAwsRegionProviderChain)2 AWSMediaStoreData (com.amazonaws.services.mediastoredata.AWSMediaStoreData)2 S3ObjectInputStream (com.amazonaws.services.s3.model.S3ObjectInputStream)2 AmazonTextract (com.amazonaws.services.textract.AmazonTextract)2 Document (com.amazonaws.services.textract.model.Document)2 S3Object (com.amazonaws.services.textract.model.S3Object)2 BufferedImage (java.awt.image.BufferedImage)2 Http (akka.http.scaladsl.Http)1 Protocol (com.amazonaws.Protocol)1 AnonymousAWSCredentials (com.amazonaws.auth.AnonymousAWSCredentials)1 AWSGlueAsyncClientBuilder (com.amazonaws.services.glue.AWSGlueAsyncClientBuilder)1