use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project quickutil by quickutil.
the class AWSS3Util method buildClient.
/**
* 获取客户端实例
*
* @param s3Name-S3Name
* @return
*/
public static AmazonS3 buildClient(String s3Name) {
AmazonS3ClientBuilder s3Builder = AmazonS3ClientBuilder.standard();
s3Builder.setCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(bucketMap.get(s3Name).get("access_key"), bucketMap.get(s3Name).get("secret_key"))));
s3Builder.setEndpointConfiguration(new EndpointConfiguration(bucketMap.get(s3Name).get("endpoint"), bucketMap.get(s3Name).get("region")));
return s3Builder.build();
}
use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project presto by prestodb.
the class GlueHiveMetastore method createAsyncGlueClient.
private static AWSGlueAsync createAsyncGlueClient(GlueHiveMetastoreConfig config, RequestMetricCollector metricsCollector) {
ClientConfiguration clientConfig = new ClientConfiguration().withMaxConnections(config.getMaxGlueConnections()).withMaxErrorRetry(config.getMaxGlueErrorRetries());
AWSGlueAsyncClientBuilder asyncGlueClientBuilder = AWSGlueAsyncClientBuilder.standard().withMetricsCollector(metricsCollector).withClientConfiguration(clientConfig);
if (config.getGlueEndpointUrl().isPresent()) {
checkArgument(config.getGlueRegion().isPresent(), "Glue region must be set when Glue endpoint URL is set");
asyncGlueClientBuilder.setEndpointConfiguration(new EndpointConfiguration(config.getGlueEndpointUrl().get(), config.getGlueRegion().get()));
} else if (config.getGlueRegion().isPresent()) {
asyncGlueClientBuilder.setRegion(config.getGlueRegion().get());
} else if (config.getPinGlueClientToCurrentRegion()) {
Region currentRegion = Regions.getCurrentRegion();
if (currentRegion != null) {
asyncGlueClientBuilder.setRegion(currentRegion.getName());
}
}
if (config.getAwsAccessKey().isPresent() && config.getAwsSecretKey().isPresent()) {
AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(new BasicAWSCredentials(config.getAwsAccessKey().get(), config.getAwsSecretKey().get()));
asyncGlueClientBuilder.setCredentials(credentialsProvider);
} else if (config.getIamRole().isPresent()) {
AWSCredentialsProvider credentialsProvider = new STSAssumeRoleSessionCredentialsProvider.Builder(config.getIamRole().get(), "roleSessionName").build();
asyncGlueClientBuilder.setCredentials(credentialsProvider);
}
return asyncGlueClientBuilder.build();
}
use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project druid by druid-io.
the class S3StorageDruidModule method getServerSideEncryptingAmazonS3Builder.
// This provides ServerSideEncryptingAmazonS3.Builder with default configs from Guice injection initially set.
// However, this builder can then be modified and have configuration(s) inside
// AmazonS3ClientBuilder and/or S3StorageConfig overridden before being built.
@Provides
public ServerSideEncryptingAmazonS3.Builder getServerSideEncryptingAmazonS3Builder(AWSCredentialsProvider provider, AWSProxyConfig proxyConfig, AWSEndpointConfig endpointConfig, AWSClientConfig clientConfig, S3StorageConfig storageConfig) {
final ClientConfiguration configuration = new ClientConfigurationFactory().getConfig();
final Protocol protocol = determineProtocol(clientConfig, endpointConfig);
final AmazonS3ClientBuilder amazonS3ClientBuilder = AmazonS3Client.builder().withCredentials(provider).withClientConfiguration(setProxyConfig(configuration, proxyConfig).withProtocol(protocol)).withChunkedEncodingDisabled(clientConfig.isDisableChunkedEncoding()).withPathStyleAccessEnabled(clientConfig.isEnablePathStyleAccess()).withForceGlobalBucketAccessEnabled(clientConfig.isForceGlobalBucketAccessEnabled());
if (StringUtils.isNotEmpty(endpointConfig.getUrl())) {
amazonS3ClientBuilder.setEndpointConfiguration(new EndpointConfiguration(endpointConfig.getUrl(), endpointConfig.getSigningRegion()));
}
return ServerSideEncryptingAmazonS3.builder().setAmazonS3ClientBuilder(amazonS3ClientBuilder).setS3StorageConfig(storageConfig);
}
use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project aws-doc-sdk-examples by awsdocs.
the class PutObject method putObject.
public static PutObjectResult putObject(String containerName, String filePath, InputStream body) throws IOException {
final String endpoint = getContainerEndpoint(containerName);
if (endpoint == null || endpoint.isEmpty()) {
System.err.println("Could not determine container endpoint!");
System.exit(1);
}
final String region = new DefaultAwsRegionProviderChain().getRegion();
final EndpointConfiguration endpointConfig = new EndpointConfiguration(endpoint, region);
final AWSMediaStoreData mediastoredata = AWSMediaStoreDataClientBuilder.standard().withEndpointConfiguration(endpointConfig).build();
final PutObjectRequest request = new PutObjectRequest().withContentType("application/octet-stream").withBody(body).withPath(filePath);
try {
return mediastoredata.putObject(request);
} catch (AWSMediaStoreException e) {
System.err.println(e.getErrorMessage());
System.exit(1);
}
return null;
}
use of com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration in project aws-doc-sdk-examples by awsdocs.
the class ListItems method main.
public static void main(String[] args) {
final String USAGE = "\n" + "To run this example, supply the name of a container and an optional path!\n" + "\n" + "Ex: ListItems <container-name> [path]\n";
if (args.length < 1) {
System.out.println(USAGE);
System.exit(1);
}
final String containerName = args[0];
String path = "";
if (args.length > 1) {
path = args[1];
}
System.out.format("Objects in MediaStore container %s, path '%s':\n", containerName, path);
final String endpoint = getContainerEndpoint(containerName);
if (endpoint == null || endpoint.isEmpty()) {
System.err.println("Could not determine container endpoint!");
System.exit(1);
}
final String region = new DefaultAwsRegionProviderChain().getRegion();
final EndpointConfiguration endpointConfig = new EndpointConfiguration(endpoint, region);
final AWSMediaStoreData mediastoredata = AWSMediaStoreDataClientBuilder.standard().withEndpointConfiguration(endpointConfig).build();
final ListItemsRequest request = new ListItemsRequest().withPath(path);
ListItemsResult result = mediastoredata.listItems(request);
List<Item> items = result.getItems();
for (Item i : items) {
System.out.printf("* (%s)\t%s\n", i.getType(), i.getName());
}
}
Aggregations