S3 Multipart Upload with SSE-KMS

2020-03-08 05:56发布

I am trying to write a utility using aws-java-sdk (1.11.230). I am able to write a file with SSE-KMS by using PutObjectRequest as follow:

PutObjectRequest putRequest = new PutObjectRequest(existingBucketName, keyName, file)
                        .withSSEAwsKeyManagementParams(kmsKeyId);

but while trying to upload it in multipart, I could not find any way to specify encryption configuration for SSE-KMS.

Could anyone please suggest a way to go through this successfully. Any suggestion will be appreciated.

Vikash Pareek

2条回答
一夜七次
2楼-- · 2020-03-08 06:16

Finally, I am able to find the solution for this. It can be done by setting headers to InitiateMultipartUploadRequest object as follow:

InitiateMultipartUploadRequest initRequest = new
                InitiateMultipartUploadRequest(bucketName, keyName);
        initRequest.putCustomRequestHeader("x-amz-server-side-encryption", "aws:kms");
        initRequest.putCustomRequestHeader("x-amz-server-side-encryption-aws-kms-key-id", kmsKey);
查看更多
我命由我不由天
3楼-- · 2020-03-08 06:22

Can also be done like this:

InitiateMultipartUploadRequest initRequest = new InitiateMultipartUploadRequest("example-bucket", "textfile.txt");      SSEAwsKeyManagementParams kms = new SSEAwsKeyManagementParams("KMS-key-alias");
initRequest.setSSEAwsKeyManagementParams(kms);
initResponse = s3Client.initiateMultipartUpload(initRequest);
查看更多
登录 后发表回答