Protecting Large Data with Envelope Encryption
This lesson explains envelope encryption, which protects data larger than the 4 KB KMS encrypts directly: data keys encrypt the data, and KMS encrypts the data keys.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how envelope encryption works.
- Explain the purpose of an encryption context.
- Explain how S3 Bucket Keys and data key caching reduce KMS requests.
How it works
KMS can encrypt at most 4 KB of data directly, and sending large amounts of data to KMS would be slow. Envelope encryption solves both problems by using two keys: a data key that encrypts the data locally, and a KMS key that protects the data key.
-
Generate a data key
The application calls
GenerateDataKey, which returns a plaintext data key and the same data key encrypted under the KMS key. -
Encrypt locally
The application encrypts the data with the plaintext data key, then discards that key from memory.
-
Store the encrypted key
The encrypted data key is stored alongside the encrypted data. To decrypt, the application asks KMS to decrypt the data key, then decrypts the data locally.
Only the small data key ever travels to KMS, so data of any size is encrypted quickly. And because the stored data key is itself encrypted, someone who obtains the stored data learns nothing without permission to decrypt the key in KMS. This is how services such as Amazon S3 and Amazon EBS encrypt data with KMS keys.
The following diagram shows the three steps above and the decryption path.

Envelope encryption
Encryption context
An encryption context is non-secret key-value data supplied when encrypting and required again to decrypt. It is recorded in CloudTrail and binds ciphertext to its purpose, such as a bucket, table or tenant. Policies can require a particular context with the kms:EncryptionContext condition key.
Request quotas and cost
KMS enforces request quotas per account and Region, and requests beyond them are throttled; every request is also charged. Workloads that encrypt or decrypt at very high rates must therefore reduce the number of KMS calls.
For Amazon S3 with SSE-KMS, S3 Bucket Keys let S3 use a bucket-level key to generate data keys for many objects, which reduces KMS calls, and their cost, by up to 99%. For application data, the AWS Encryption SDK implements envelope encryption and can cache data keys, so many messages are encrypted with one data key instead of a KMS call for each.
KMS throttling
KMS throttling from a busy bucket
A data pipeline writes millions of small objects an hour to a bucket encrypted with SSE-KMS. Uploads start failing with KMS throttling errors, and the KMS bill has grown sharply.
| Cause | Fix |
|---|---|
| Each object needs its own data key from KMS | Enable S3 Bucket Keys, so S3 derives object keys from a bucket-level key |
| Request rate above the Regional KMS quota | Bucket Keys cut KMS requests by up to 99%; a quota increase is the alternative |
Envelope encryption still protects every object, but KMS is now called rarely. Applications that encrypt data themselves achieve the same effect with the AWS Encryption SDK's data key caching.
Why is data larger than 4 KB not sent to KMS for encryption?
Show answer
KMS encrypts at most 4 KB directly. Larger data is encrypted locally with a data key, and only the small data key is protected by KMS.
Exam Tips
Remember for the exam
- To encrypt data larger than 4 KB, use envelope encryption with data keys.
- For KMS throttling or cost from busy SSE-KMS buckets, use S3 Bucket Keys.
- To bind ciphertext to a particular context and record it in logs, use an encryption context.
- For client-side encryption of application data, use the AWS Encryption SDK.