AWS in 1 Min · Episode 139

AWS KMS Part 2, envelope encryption explained

Envelope encryption. Watch the one-minute video, then read the details.

David Gomez1:17 video · 3 min read

"KMS encrypts all your data itself." It doesn't, and it couldn't do it well. Sending terabytes over the network to an API would be slow and expensive, and the KMS Encrypt operation accepts at most 4,096 bytes of plaintext with a symmetric key. Instead, AWS services and the AWS Encryption SDK use envelope encryption: your data is encrypted locally with a data key, and only that small data key is protected by KMS.

The idea in one sentence

Envelope encryption means encrypting data with a data key, and then encrypting the data key under another key. On AWS, that other key is your KMS key, which never leaves KMS unencrypted. Think of a box locked with a cheap padlock, with the padlock's key sealed in an envelope that only KMS can open, taped to the box.

Encrypting, step by step

  1. Ask KMS for a data key. Call GenerateDataKey with your KMS key. KMS returns two copies of a fresh data key: one in plaintext, and one encrypted under your KMS key.
  2. Encrypt locally. Use the plaintext data key with a fast symmetric algorithm such as AES-GCM to encrypt your data, on your own machine or inside the AWS service. Then erase the plaintext data key from memory as soon as you can.
  3. Store them together. Save the encrypted data key next to the encrypted data. It is safe to store it in the open, because only KMS can decrypt it.

Decrypting

To read the data, send just the encrypted data key to KMS with Decrypt. KMS checks the key policy and IAM; if you are allowed, it returns the plaintext data key, and you decrypt the data locally. Every one of those Decrypt calls lands in CloudTrail, so access stays auditable even though the bulk work happens outside KMS.

Why it's done this way

  • Speed: symmetric encryption of big data runs locally; only a few hundred bytes go to KMS.
  • Protected keys: the data key is never stored in plaintext.
  • Cheap re-keying: to move data under a different KMS key, you re-encrypt only the small data key, not the whole dataset.
  • Control stays central: revoke access to the KMS key and the data keys can no longer be opened.

A common mistake is writing your own scheme that keeps the plaintext data key on disk "for performance". Use the AWS Encryption SDK or the service's built-in encryption instead; they handle the envelope format, encryption context and key caching for you.

Where AI fits

AI work moves large datasets: training corpora, document collections for retrieval, model artifacts. When those live in Amazon S3 with SSE-KMS, S3 uses envelope encryption under the hood: each object is encrypted with a data key, and only data keys travel to KMS. With S3 Bucket Keys turned on, S3 uses a short-lived bucket-level key to create those data keys, which reduces request traffic from S3 to KMS and the KMS request cost that comes with it. That matters when a training job reads or writes millions of objects. See also SSE-S3 vs SSE-KMS.

Quick recap

  • KMS doesn't encrypt your big data; Encrypt takes at most 4 KB.
  • A data key encrypts the data; your KMS key encrypts the data key.
  • Store the encrypted data key with the data; send only that small key to KMS to decrypt.
  • For big S3 datasets, turn on S3 Bucket Keys to cut KMS calls.
AWS in 1 Min #139 · 1:17

Need an AWS expert on your team?

I'm David, an AWS expert and fractional cloud consultant. I work alongside your team to run your cloud and infrastructure: architecture, security, cost and day-to-day operations. You get senior AWS experience when you need it, without the cost of a full-time hire.

  • Architecture reviews and a clear plan for what to fix first
  • Security hardening: IAM, networking, audits
  • Lower AWS bills without slowing your team down
  • Hands-on help with AI workloads on AWS