Example usage for com.amazonaws.services.s3.model CopyObjectRequest withSSEAwsKeyManagementParams

List of usage examples for com.amazonaws.services.s3.model CopyObjectRequest withSSEAwsKeyManagementParams

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model CopyObjectRequest withSSEAwsKeyManagementParams.

Prototype

public CopyObjectRequest withSSEAwsKeyManagementParams(SSEAwsKeyManagementParams sseAwsKeyManagementParams) 

Source Link

Document

Sets the AWS Key Management System parameters used to encrypt the object on server side.

Usage

From source file:io.druid.storage.s3.KmsServerSideEncryption.java

License:Apache License

@Override
public CopyObjectRequest decorate(CopyObjectRequest request) {
    return request.withSSEAwsKeyManagementParams(
            keyId == null ? new SSEAwsKeyManagementParams() : new SSEAwsKeyManagementParams(keyId));
}

From source file:org.finra.dm.dao.impl.S3DaoImpl.java

License:Apache License

@Override
public S3FileTransferResultsDto copyFile(final S3FileCopyRequestParamsDto params) throws InterruptedException {
    LOGGER.info(/*  w  ww  .  j a v a2s .  co m*/
            String.format("Copying S3 object from s3://%s/%s to s3://%s/%s...", params.getSourceBucketName(),
                    params.getS3KeyPrefix(), params.getTargetBucketName(), params.getS3KeyPrefix()));

    // Perform the copy.
    S3FileTransferResultsDto results = performTransfer(params, new Transferer() {
        @Override
        public Transfer performTransfer(TransferManager transferManager) {
            // Create a copy request.
            CopyObjectRequest copyObjectRequest = new CopyObjectRequest(params.getSourceBucketName(),
                    params.getS3KeyPrefix(), params.getTargetBucketName(), params.getS3KeyPrefix());
            copyObjectRequest
                    .withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(params.getKmsKeyId()));

            return s3Operations.copyFile(copyObjectRequest, transferManager);
        }
    });

    LOGGER.info("File \"" + params.getS3KeyPrefix() + "\" contains " + results.getTotalBytesTransferred()
            + " byte(s) which was successfully copied from source bucket:\"" + params.getSourceBucketName()
            + "\" to target bucket:\"" + params.getTargetBucketName() + "\" in "
            + DmDateUtils.formatDuration(results.getDurationMillis(), true));

    LOGGER.info(String.format("Overall transfer rate: %.2f kBytes/s (%.2f Mbits/s)",
            getTransferRateInKilobytesPerSecond(results.getTotalBytesTransferred(),
                    results.getDurationMillis()),
            getTransferRateInMegabitsPerSecond(results.getTotalBytesTransferred(),
                    results.getDurationMillis())));

    return results;
}

From source file:org.finra.herd.dao.impl.S3DaoImpl.java

License:Apache License

@Override
public S3FileTransferResultsDto copyFile(final S3FileCopyRequestParamsDto params) throws InterruptedException {
    LOGGER.info(/*from w w  w .  j  ava 2s  .c o m*/
            "Copying S3 object... sourceS3Key=\"{}\" sourceS3BucketName=\"{}\" targetS3Key=\"{}\" targetS3BucketName=\"{}\"",
            params.getSourceObjectKey(), params.getSourceBucketName(), params.getTargetObjectKey(),
            params.getTargetBucketName());

    // Perform the copy.
    S3FileTransferResultsDto results = performTransfer(params, new Transferer() {
        @Override
        public Transfer performTransfer(TransferManager transferManager) {
            // Create a copy request.
            CopyObjectRequest copyObjectRequest = new CopyObjectRequest(params.getSourceBucketName(),
                    params.getSourceObjectKey(), params.getTargetBucketName(), params.getTargetObjectKey());

            // If KMS Key ID is specified, set the AWS Key Management System parameters to be used to encrypt the object.
            if (StringUtils.isNotBlank(params.getKmsKeyId())) {
                copyObjectRequest
                        .withSSEAwsKeyManagementParams(new SSEAwsKeyManagementParams(params.getKmsKeyId()));
            }
            // Otherwise, specify the server-side encryption algorithm for encrypting the object using AWS-managed keys.
            else {
                ObjectMetadata metadata = new ObjectMetadata();
                metadata.setSSEAlgorithm(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
                copyObjectRequest.setNewObjectMetadata(metadata);
            }

            return s3Operations.copyFile(copyObjectRequest, transferManager);
        }
    });

    LOGGER.info(
            "Copied S3 object. sourceS3Key=\"{}\" sourceS3BucketName=\"{}\" targetS3Key=\"{}\" targetS3BucketName=\"{}\" "
                    + "totalBytesTransferred={} transferDuration=\"{}\"",
            params.getSourceObjectKey(), params.getSourceBucketName(), params.getTargetObjectKey(),
            params.getTargetBucketName(), results.getTotalBytesTransferred(),
            HerdDateUtils.formatDuration(results.getDurationMillis()));

    logOverallTransferRate(results);

    return results;
}