AWS Developer Tools Blog
Generating Amazon S3 Pre-signed URLs with SSE-KMS (Part 2)
To continue from the previous blog, I will provide specific code examples that show how you can generate and consume pre-signed URLs using server-side encryption with AWS Key Management Service (SSE-KMS). A pre-requisite to this option is that you must be using Signature Version 4 (SigV4). You can enable SigV4 in the AWS SDK for Java in various ways, including using S3-specific system properties. Here, I will provide a less known but programmatic way to achieve that by explicitly configuring the signer. The code samples assume the version of the AWS SDK for Java to be 1.9.31 or later.
Configure AmazonS3Client to use SigV4
Once this is in place, you are good to go.
Server-Side Encryption with AWS Key Management Service (SSE-KMS)
Example A. Here’s how to generate a pre-signed PUT URL using SSE-KMS:
In the above example, Amazon S3 will make use of the default KMS master key for S3 that is automatically created for you. (See Creating Keys in AWS Key Management Service for more information on how you can set up your AWS KMS customer master keys.)
However, you can also choose to explicitly specify your KMS customer master key id as part of the pre-signed URLs.
Example B. Here’s how to generate a pre-signed PUT URL using SSE-KMS with an explicit KMS customer master key id:
Here’s how to make use of the generated pre-signed PUT URL (from Example A) via the Apache HttpClient (4.3):
Here’s how to make use of the generated pre-signed PUT URL from (Example B) via the Apache HttpClient (4.3):
Here’s how to generate a pre-signed GET URL for use with SSE-KMS:
(Note in particular that generating a pre-signed GET URL for an S3 object encrypted using SSE-KMS is as simple as generating a regular pre-signed URL!)
Here’s how to make use of the generated pre-signed GET URL via the Apache HttpClient (4.3):
In the next blog (Part 3), I will provide specific code examples that show how you can generate and consume pre-signed URLs using server side encryption with Amazon S3-managed keys (SSE-S3).
Stay tuned!