Encryption with KMS
Envelope encryption with AWS KMS: data keys, key policies and IAM, encryption context, rotation, deletion, and how S3 and EBS use keys.
Policy documents and evaluation logicS3 buckets, objects and consistencyEBS volumes and snapshots
Encryption with KMS
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- KMS keys stay inside KMS. You ask it to encrypt, decrypt or generate data keys, and every request is authorized and logged.
- Envelope encryption uses a fresh data key for the data and a KMS key to wrap that data key. The wrapped key is stored next to the ciphertext.
- The key policy is the root of access to a key. IAM policies work only if the key policy lets the account delegate to IAM.
- Reading encrypted data needs permission on the data and permission to use the key, so a key is a second lock you control.
- Rotation adds new key material and keeps the old for decryption. Deleting a key destroys the ability to read everything under it.
- Customer managed keys cost money per key and per request. S3 Bucket Keys cut the request volume for SSE-KMS.
The hard part isn’t the cipher
Encrypting data is easy: any library will do AES. The hard part is the key. Put it next to the data and you’ve locked the door and taped the key to it. Put it in an environment variable and everyone who can read the config can read everything, with no record of who did.
AWS Key Management Service keeps keys inside hardware security modules and never hands them out. You send a request, KMS checks permissions, performs the operation and logs it in CloudTrail. It’s a bank vault with a clerk: you don’t take the master key home, you ask the clerk to open things.
Envelope encryption
The vault clerk won’t encrypt your whole database. Encrypt accepts at most 4,096 bytes, and shipping gigabytes over the network would be slow anyway. So you use two layers:
- Ask KMS to
GenerateDataKey. It returns a new key twice: in plaintext, and encrypted under your KMS key. - Encrypt your data locally with the plaintext copy, then discard it.
- Store the encrypted (wrapped) data key beside the ciphertext.
To read, send the wrapped key to Decrypt, get the plaintext data key and decrypt locally.
dk = kms.generate_data_key(KeyId="alias/orders", KeySpec="AES_256",
EncryptionContext={"tenant": "acme"})
blob = AESGCM(dk["Plaintext"]).encrypt(nonce, payload, None)
store(dk["CiphertextBlob"], nonce, blob)
Run against a local KMS emulator, encrypting a million bytes this way gave a 1,000,016-byte ciphertext and a 96-byte wrapped key, and decrypting returned the million bytes. AWS’s Encryption SDK does this properly so you don’t hand-roll it.
The EncryptionContext is a set of non-secret labels bound to the ciphertext. Decrypt must supply the same ones. In the emulator, asking with tenant: globex or no context failed with InvalidCiphertextException. Context also appears in CloudTrail and can be required in policy conditions.
S3, EBS, RDS and most other services use this same pattern for you.
Who may use a key
Every key has a key policy, and it is the root of all access to that key. This is unlike most resources: an IAM allow alone does nothing unless the key policy opens the door. The usual opening statement is:
{ "Sid": "Enable IAM User Permissions", "Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::123456789012:root" },
"Action": "kms:*", "Resource": "*" }
Here root means the account, which may then delegate with IAM. Separate who administers a key from who uses it. Someone who can edit the policy can grant themselves use, so keep that group small. Grants are a third mechanism, which services use for temporary, narrow access.
This gives you a second lock. A principal needs permission on the object and kms:Decrypt on its key.
Kinds of key
- AWS owned keys live in a service’s account. You can’t see or manage them, and they’re free to you.
- AWS managed keys (
aws/s3,aws/ebs) appear in your account, but you can’t change their policy, so they can’t be shared across accounts. AWS calls them a legacy type and hasn’t created them for new services since 2021. - Customer managed keys are yours: your policy, rotation, sharing and deletion. They cost $1 a month each plus per-request charges (KMS pricing, November 2026).
Use customer managed keys where you need control or evidence. Defaults are fine elsewhere.
Rotation and deletion
With automatic rotation enabled, KMS creates new key material every 365 days by default. The key ID and ARN stay the same, and old material is kept for decryption. It doesn’t re-encrypt anything.
Deletion is the dangerous operation. It needs a waiting period of 7 to 30 days, 30 by default, and afterwards everything wrapped under the key is gone for good. Disable first and watch for failures. Keys are Regional, so copying encrypted snapshots or replicating objects elsewhere needs a key in the destination, or a multi-Region key.
S3 and EBS
S3 encrypts every new object with SSE-S3 by default at no charge. Choosing SSE-KMS adds your key’s permissions and audit trail, and a KMS request quota and cost; turning on an S3 Bucket Key reduces those requests, by up to 99% according to AWS. SSE-C, where you send your own key with each request, has been blocked by default on new buckets since April 2026. EBS encryption can be switched on by default per Region.
At-rest encryption protects stored bytes. It doesn’t stop a principal who is allowed both to read and to decrypt.
About the video
The embed is DheerajTechInsight’s 22-minute AWS KMS tutorial from November 2025. Its chapters cover what KMS is, key types, symmetric and asymmetric keys, how encryption works including envelopes, key policies and permissions, creating a customer managed key, service integrations and good practice. I judged it from chapters and description only; its audio is flagged as original US English.
What was run: the envelope code, the context failures and the default policy ran against moto 5.1.22. moto also decrypted with a disabled key, which real KMS refuses, so it doesn’t enforce key state or policy here. Limits, rotation, deletion and key types come from the KMS developer guide, checked in November 2026.
Check yourself
Why not send a 1 GB file to KMS to be encrypted?
The Encrypt API takes at most 4,096 bytes. Instead you ask for a data key, encrypt the file locally with it and store the wrapped copy of the data key with the file.
A role has s3:GetObject on a bucket that uses SSE-KMS with a customer managed key, but downloads are denied. What is missing?
Permission to call kms:Decrypt on that key, allowed by the key policy directly or by an IAM policy the key policy enables.
You enable automatic rotation. Do you need to re-encrypt old objects?
No. KMS keeps earlier key material and picks the right one when decrypting. Rotation affects what new encryption uses, and doesn't change data already written or data keys already issued.
Why is disabling a key a better first step than deleting it?
Disabling can be undone. Deletion, after its waiting period of 7 to 30 days, is permanent and makes all data wrapped under the key unreadable.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.