Search in sources :

Example 1 with EndpointConfiguration

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();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 2 with EndpointConfiguration

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();
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AWSGlueAsyncClientBuilder(com.amazonaws.services.glue.AWSGlueAsyncClientBuilder) AWSGlueAsyncClientBuilder(com.amazonaws.services.glue.AWSGlueAsyncClientBuilder) Region(com.amazonaws.regions.Region) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) ClientConfiguration(com.amazonaws.ClientConfiguration) AWSCredentialsProvider(com.amazonaws.auth.AWSCredentialsProvider) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Example 3 with EndpointConfiguration

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);
}
Also used : AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) ClientConfigurationFactory(com.amazonaws.ClientConfigurationFactory) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) Protocol(com.amazonaws.Protocol) ClientConfiguration(com.amazonaws.ClientConfiguration) Provides(com.google.inject.Provides)

Example 4 with EndpointConfiguration

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;
}
Also used : DefaultAwsRegionProviderChain(com.amazonaws.regions.DefaultAwsRegionProviderChain) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) AWSMediaStoreData(com.amazonaws.services.mediastoredata.AWSMediaStoreData) AWSMediaStoreException(com.amazonaws.services.mediastore.model.AWSMediaStoreException) PutObjectRequest(com.amazonaws.services.mediastoredata.model.PutObjectRequest)

Example 5 with EndpointConfiguration

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());
    }
}
Also used : DefaultAwsRegionProviderChain(com.amazonaws.regions.DefaultAwsRegionProviderChain) Item(com.amazonaws.services.mediastoredata.model.Item) EndpointConfiguration(com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration) AWSMediaStoreData(com.amazonaws.services.mediastoredata.AWSMediaStoreData) ListItemsRequest(com.amazonaws.services.mediastoredata.model.ListItemsRequest) ListItemsResult(com.amazonaws.services.mediastoredata.model.ListItemsResult)

Aggregations

EndpointConfiguration (com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration)12 ClientConfiguration (com.amazonaws.ClientConfiguration)5 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)5 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)4 Region (com.amazonaws.regions.Region)3 AmazonS3ClientBuilder (com.amazonaws.services.s3.AmazonS3ClientBuilder)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 AmazonS3 (com.amazonaws.services.s3.AmazonS3)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