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();
}
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();
}
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;
}
Aggregations