List of usage examples for com.amazonaws.services.s3 AmazonS3Builder enablePathStyleAccess
public Subclass enablePathStyleAccess()
Enables path style access for clients built via this builder.
Amazon S3 supports virtual-hosted-style and path-style access in all Regions.
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 w w w .ja va 2 s .c om 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(); }