Example usage for com.amazonaws.services.s3 AmazonS3ClientBuilder standard

List of usage examples for com.amazonaws.services.s3 AmazonS3ClientBuilder standard

Introduction

In this page you can find the example usage for com.amazonaws.services.s3 AmazonS3ClientBuilder standard.

Prototype

public static AmazonS3ClientBuilder standard() 

Source Link

Usage

From source file:com.netflix.spinnaker.config.secrets.engines.S3SecretEngine.java

License:Apache License

@Override
protected InputStream downloadRemoteFile(EncryptedSecret encryptedSecret) throws IOException {
    String region = encryptedSecret.getParams().get(STORAGE_REGION);
    String bucket = encryptedSecret.getParams().get(STORAGE_BUCKET);
    String objName = encryptedSecret.getParams().get(STORAGE_FILE_URI);

    AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard().withRegion(region);

    AmazonS3 s3Client = s3ClientBuilder.build();

    try {//  w ww  .j a  v a 2 s .  c  o  m
        S3Object s3Object = s3Client.getObject(bucket, objName);
        return s3Object.getObjectContent();

    } catch (AmazonClientException ex) {
        String msg = String.format(
                "Error reading contents of S3. Region: %s, Bucket: %s, Object: %s. "
                        + "Check connectivity and permissions to that bucket: %s ",
                region, bucket, objName, ex.toString());
        throw new IOException(msg);
    }
}

From source file:com.netflix.spinnaker.kork.secrets.engines.S3SecretEngine.java

License:Apache License

@Override
protected InputStream downloadRemoteFile(EncryptedSecret encryptedSecret) throws IOException {
    String region = encryptedSecret.getParams().get(STORAGE_REGION);
    String bucket = encryptedSecret.getParams().get(STORAGE_BUCKET);
    String objName = encryptedSecret.getParams().get(STORAGE_FILE_URI);

    AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard().withRegion(region);

    AmazonS3 s3Client = s3ClientBuilder.build();

    try {//  w  w  w  .  j  a v a 2  s .c  o  m
        if (!s3Client.doesBucketExistV2(bucket)) {
            throw new SecretException(
                    String.format("S3 Bucket does not exist. Bucket: %s, Region: %s", bucket, region));
        }

        S3Object s3Object = s3Client.getObject(bucket, objName);

        return s3Object.getObjectContent();
    } catch (AmazonS3Exception ex) {
        StringBuilder sb = new StringBuilder("Error reading contents of S3 -- ");
        if (403 == ex.getStatusCode()) {
            sb.append(String.format(
                    "Unauthorized access. Check connectivity and permissions to the bucket. -- Bucket: %s, Object: %s, Region: %s.\n"
                            + "Error: %s ",
                    bucket, objName, region, ex.toString()));
        } else if (404 == ex.getStatusCode()) {
            sb.append(String.format(
                    "Not found. Does secret file exist? -- Bucket: %s, Object: %s, Region: %s.\nError: %s",
                    bucket, objName, region, ex.toString()));
        } else {
            sb.append(String.format("Error: %s", ex.toString()));
        }
        throw new SecretException(sb.toString());
    } catch (AmazonClientException ex) {
        throw new SecretException(
                String.format("Error reading contents of S3. Bucket: %s, Object: %s, Region: %s.\nError: %s",
                        bucket, objName, region, ex.toString()));
    }
}

From source file:com.openlattice.aws.AwsS3Pod.java

License:Open Source License

public static AmazonS3 newS3Client(AmazonLaunchConfiguration awsConfig) {
    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard();
    builder.setRegion(Region.getRegion(awsConfig.getRegion().or(Regions.DEFAULT_REGION)).getName());
    return builder.build();
}

From source file:com.streamsets.datacollector.lib.emr.S3Manager.java

License:Apache License

private AmazonS3 getS3Client() {
    AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(pipelineEmrConfigs.getAccessKey(), pipelineEmrConfigs.getSecretKey()));

    AmazonS3 s3Client = AmazonS3ClientBuilder.standard().withRegion(pipelineEmrConfigs.getUserRegion())
            .withCredentials(credentialsProvider).build();
    return s3Client;
}

From source file:com.streamsets.pipeline.lib.aws.s3.S3Accessor.java

License:Apache License

AmazonS3ClientBuilder createAmazonS3ClientBuilder() {
    return AmazonS3ClientBuilder.standard();
}

From source file:com.streamsets.pipeline.stage.common.s3.S3ConnectionBaseConfig.java

License:Apache License

private void createConnection(Stage.Context context, String configPrefix, ProxyConfig proxyConfig,
        List<Stage.ConfigIssue> issues, int maxErrorRetries) throws StageException {
    AWSCredentialsProvider credentials = AWSUtil.getCredentialsProvider(awsConfig);
    ClientConfiguration clientConfig = AWSUtil.getClientConfiguration(proxyConfig);

    if (maxErrorRetries >= 0) {
        clientConfig.setMaxErrorRetry(maxErrorRetries);
    }//ww  w . j  a v  a  2s .co  m

    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withCredentials(credentials)
            .withClientConfiguration(clientConfig).withChunkedEncodingDisabled(awsConfig.disableChunkedEncoding)
            .withPathStyleAccessEnabled(true);

    if (region == AwsRegion.OTHER) {
        if (endpoint == null || endpoint.isEmpty()) {
            issues.add(context.createConfigIssue(Groups.S3.name(), configPrefix + "endpoint",
                    Errors.S3_SPOOLDIR_10));
            return;
        }
        builder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, null));
    } else {
        builder.withRegion(region.getId());
    }
    s3Client = builder.build();
}

From source file:com.streamsets.pipeline.stage.origin.s3.AmazonS3Runnable.java

License:Apache License

private AmazonS3 createConnection() throws StageException {
    AwsRegion region = s3ConfigBean.s3Config.region;
    AWSConfig awsConfig = s3ConfigBean.s3Config.awsConfig;
    int maxErrorRetries = s3ConfigBean.s3Config.getMaxErrorRetries();

    AWSCredentialsProvider credentials = AWSUtil.getCredentialsProvider(awsConfig);
    ClientConfiguration clientConfig = AWSUtil.getClientConfiguration(s3ConfigBean.proxyConfig);

    if (maxErrorRetries >= 0) {
        clientConfig.setMaxErrorRetry(maxErrorRetries);
    }//from w ww.  j a  v a2  s  . c om

    AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withCredentials(credentials)
            .withClientConfiguration(clientConfig).withChunkedEncodingDisabled(awsConfig.disableChunkedEncoding)
            .withPathStyleAccessEnabled(true);

    builder.withRegion(region.getId());
    return builder.build();
}

From source file:com.thinkbiganalytics.kylo.catalog.aws.S3FileSystemProvider.java

License:Apache License

/**
 * Creates an S3 client with the standard credential providers.
 *//*w w w.j a  v  a 2s .  c o  m*/
@VisibleForTesting
protected AmazonS3 createS3Client(@Nonnull final URI uri, @Nonnull final Configuration conf) {
    // Create list of credential providers
    final List<AWSCredentialsProvider> credentials = new ArrayList<>();
    getCustomCredentialsProvider(uri, conf).ifPresent(credentials::add);
    getBasicCredentialsProvider(uri, conf).ifPresent(credentials::add);
    credentials.add(InstanceProfileCredentialsProvider.getInstance());

    // Create client
    final AWSCredentialsProviderChain chain = new AWSCredentialsProviderChain(credentials);
    chain.setReuseLastProvider(true);
    return AmazonS3ClientBuilder.standard().withCredentials(chain).build();
}

From source file:com.universal.storage.UniversalS3Storage.java

License:Open Source License

/**
 * This constructor receives the settings for this new FileStorage instance.
 * //w  w  w.j a v a 2 s.  c  o m
 * @param settings for this new FileStorage instance.
 */
public UniversalS3Storage(UniversalSettings settings) {
    super(settings);
    this.s3client = AmazonS3ClientBuilder.standard().withRegion(Regions.fromName(settings.getS3Region()))
            .withCredentials(new UniversalProfileCredentialsProvider(this.settings)).build();
}

From source file:com.yahoo.athenz.auth.impl.aws.AwsPrivateKeyStore.java

License:Apache License

private static AmazonS3 initAmazonS3() {
    String s3Region = System.getProperty(ATHENZ_PROP_AWS_S3_REGION);
    if (null != s3Region && !s3Region.isEmpty()) {
        return AmazonS3ClientBuilder.standard().withRegion(s3Region).build();
    }//from   ww w  .  ja v a2  s.c o  m
    return AmazonS3ClientBuilder.defaultClient();
}