AWS KMS keys and envelope encryption
KMS key types, ownership models, envelope encryption, data key APIs, aliases, multi-Region keys and deletion. The base of almost every encryption question.
Exam tasks: 5.2.1 (choose KMS and server- or client-side encryption), 5.3.5 (create and manage KMS keys across one or many Regions)
The decision: which kind of KMS key protects this data, and how does it move between Regions and retire safely?
AWS KMS is a regional managed service that creates and controls KMS keys. KMS keys never leave KMS unencrypted and run inside HSMs validated to FIPS 140-3 Security Level 3. A KMS key directly encrypts at most 4,096 bytes, so real data is protected with envelope encryption.
Which one to use
The tables below compare the three ownership models and the key specs the tree ends on.
Who owns the key
| AWS owned | AWS managed | Customer managed | |
|---|---|---|---|
| Where it lives | Service's own account, invisible to you | Your account, alias aws/<service> | Your account |
| Key policy | None you can see | Written by AWS, read-only | Yours |
| Rotation | Service decides | Every year, automatic, can't change | Off by default; automatic every 90–2,560 days, plus on demand |
| Usable by other accounts | No | No | Yes, through the key policy |
| Disable, schedule deletion | No | No | Yes |
| Shows in your CloudTrail | No | Yes | Yes |
| Typical signal | "Encryption with no management" | "Audit, no control needed" | "Separation of duties", "revoke", "cross-account", "custom rotation" |
Rules that follow from the table:
- AWS managed keys can only be used through the service that owns them and only by principals in your account. You cannot share resources encrypted under one with another account.
- The
aws/alias prefix is reserved. You cannot create an alias that starts with it. - AWS managed keys are not created for new services any more. New services default to AWS owned keys.
Exam signal
A question that says a DynamoDB table, SQS queue or EventBridge bus "must be encrypted, with no additional cost or management" is satisfied by the default AWS owned key. As soon as the question adds "the security team must be able to audit and revoke access", move to a customer managed key.
Legacy
Older material says customer master key (CMK). The current terms are KMS key, customer managed key and AWS managed key. Older guides also say AWS managed keys rotate every three years. That changed to yearly in May 2022.
Key types
| Key spec | Key usage | Notes |
|---|---|---|
SYMMETRIC_DEFAULT (AES-256-GCM) | Encrypt and decrypt | The only type AWS services use for server-side encryption. Never leaves KMS unencrypted. Every type has a key that is created once and cannot change its usage |
| RSA 2048, 3072, 4096 | Encrypt and decrypt, or sign and verify | Download the public key to encrypt or verify outside AWS |
| ECC NIST (P-256, P-384, P-521), ECC SECG P-256K1 | Sign and verify, or key agreement | Signing for code, JWTs and blockchain-style workloads |
| ML-DSA 44, 65, 87 | Sign and verify | Post-quantum signatures |
| HMAC 224 to 512 | Generate and verify MAC | Tamper-evident tokens without sharing a secret |
- Key usage is fixed at creation. An RSA key created for signing can't later encrypt.
- Asymmetric and HMAC keys don't rotate automatically or on demand. "Rotate" them by creating a new key and moving the alias.
- Asymmetric private keys never leave KMS. If a partner needs to verify your signatures offline, give them the
public key from
GetPublicKey.
Data key APIs
| API | Returns | Use when |
|---|---|---|
Encrypt / Decrypt | Ciphertext or plaintext | Small data, up to 4,096 bytes |
GenerateDataKey | Plaintext key and wrapped key | Encrypt data now on the caller |
GenerateDataKeyWithoutPlaintext | Wrapped key only | Create keys ahead of time. A different component calls Decrypt later, so the creator never sees plaintext |
ReEncrypt | New ciphertext | Move ciphertext to another key without exposing plaintext |
Delete the plaintext data key from memory after use.
- Heavy request rates can hit KMS throttling. Use S3 Bucket Keys and data key caching in the AWS Encryption SDK before you ask for a quota increase.
- Encryption context, the optional additional authenticated data on these calls, is covered on KMS key policy, IAM and grants.
Exam signal
Data keys, large files or "encrypt more than 4 KB" means envelope encryption with GenerateDataKey. "Never expose the plaintext key to the writer service" means GenerateDataKeyWithoutPlaintext.
Aliases
- An alias is a friendly name such as
alias/app-prod. One key can have many aliases, an alias points to one key, and alias names are unique per account and Region. - Applications that call by alias survive manual rotation. Run
UpdateAliasto repoint it. CreateGrantand some other calls do not accept an alias. Use the key ID or ARN.- Cross-account calls need the key ARN or alias ARN.
Multi-Region keys
- Create a primary key, then call
ReplicateKey. Replicas share key material, so ciphertext from one Region decrypts in another without re-encryption. - Key policy, grants, aliases and tags are independent per Region. Rotation settings are shared and managed from the primary.
UpdatePrimaryRegionswaps primary and replica roles.- To delete a primary key, schedule deletion of every replica first. A replica can be deleted at any time.
- Use them for client-side encryption of data that moves between Regions, global tables with the Database Encryption SDK, and signing in several Regions. AWS services that re-encrypt on replication (S3 Replication, EBS snapshot copy, RDS cross-Region replicas) work fine with separate single-Region keys.
- You can promote a replica to primary after losing the primary Region.
Multi-Region by default
"Encrypt all data with one key that works everywhere" isn't a best practice. Data sovereignty rules often require that ciphertext is not decryptable outside its Region. Choose multi-Region keys only when a workload needs the same ciphertext in more than one Region.
Deleting a key
| Item | Fact |
|---|---|
| Waiting period | 7 to 30 days, default 30 |
| During waiting period | State is Pending deletion. Cannot be used for crypto operations. Deletion can be cancelled |
| After it ends | Key, aliases and metadata are gone. Data encrypted under it is unrecoverable |
| Safer option | Disable the key. It can be re-enabled |
| Detection | CloudTrail logs the schedule and delete events. A CloudWatch alarm can watch for use attempts during the wait |
- Disable first if you suspect a key is unused. Watch CloudTrail for failed requests, then schedule deletion.
- An EventBridge rule or CloudWatch alarm on use attempts during
PendingDeletioncatches forgotten dependencies before the key is gone. - An SCP that denies
kms:ScheduleKeyDeletionto everyone except a break-glass role is a common guardrail.
Exam trap
A deleted KMS key cannot be recovered, and you cannot recreate it by importing the same material. Cancel deletion while the key is Pending deletion, or disable instead of deleting.
Scenarios
An asymmetric signing key keeps the private key inside KMS HSMs, logs every Sign call in CloudTrail, and lets anyone verify with the public key. HMAC verification needs the secret itself, which can't be shared out of KMS. A data key pair gives the application the plaintext private key, and a key stored in Secrets Manager was generated and used outside an HSM.
Disabling is reversible and shows who still calls the key. Scheduling deletion with an alarm on use attempts gives a final safety net, and you can cancel during the waiting period. Deleting an alias leaves the key intact. Rotation doesn't re-encrypt anything. A key always has a key policy; you can't simply remove it.
Related
- KMS key policy, IAM and grants
- KMS rotation and imported key material
- CloudHSM and KMS custom key stores
- S3 encryption options
Further reading
Domain 5 · Data protection
18% of the exam. Who controls the keys, how traffic stays encrypted, how stored data survives deletion and ransomware, and how secrets and sensitive fields stay out of sight.
KMS key policy, IAM and grants
How KMS authorizes a request. Key policy, IAM policy and grants, the root principal statement, condition keys and encryption context.