Search in sources :

Example 61 with Region

use of com.amazonaws.services.s3.model.Region 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 62 with Region

use of com.amazonaws.services.s3.model.Region 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)

Example 63 with Region

use of com.amazonaws.services.s3.model.Region 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

AmazonS3 (com.amazonaws.services.s3.AmazonS3)18 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)17 IOException (java.io.IOException)12 AmazonServiceException (com.amazonaws.AmazonServiceException)11 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)11 Test (org.junit.Test)10 AmazonClientException (com.amazonaws.AmazonClientException)9 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)9 Regions (com.amazonaws.regions.Regions)9 HashMap (java.util.HashMap)9 Date (java.util.Date)8 Map (java.util.Map)8 ClientConfiguration (com.amazonaws.ClientConfiguration)7 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)7 S3Object (com.amazonaws.services.s3.model.S3Object)7 AWSKMS (com.amazonaws.services.kms.AWSKMS)6 TransferManager (com.amazonaws.services.s3.transfer.TransferManager)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 FileNotFoundException (java.io.FileNotFoundException)6 InputStream (java.io.InputStream)6