Skip to main content
Welcome — this lesson explains AWS Key Management Service (KMS) and how to use Customer Managed Keys (CMKs) for data protection. Topics covered:
  • KMS overview and core concepts
  • Envelope encryption data flow
  • CMK lifecycle and access control (key policies, grants, IAM)
  • Common KMS integrations and implementation patterns
  • Key rotation strategies and best practices
This guide preserves diagrams and examples to help you understand how KMS fits into a secure AWS architecture. Data protection overview AWS KMS is the centralized key management service used across the AWS platform. If you require dedicated hardware security modules, see AWS CloudHSM. KMS integrates with many AWS services (for example: SSE‑KMS for Amazon S3, EBS encryption, RDS, Lambda), enabling consistent, auditable encryption controls. Enterprises use KMS to meet regulatory and audit requirements, enforce granular encryption access (including cross-account and cross-region use cases), and centralize key governance.
A presentation slide titled "Scenario: The Data Protection Challenge" that lists data protection challenges (regulatory requirements, granular key control, cross-account/cross-region, audit requirements) on the left and AWS encryption services (Amazon S3, EBS, Redshift, RDS) on the right. Arrows link the cross-account/cross-region requirement to Amazon Redshift and RDS.
KMS fundamentals KMS provides key generation, storage, use, and lifecycle management. Use CMKs when you need control over key policies, key material, or cross-account access. Key concepts at a glance: KMS also supports importing your own key material and issuing grants (temporary scoped permissions).
A presentation slide titled "AWS KMS Fundamentals" with two boxes listing "Core KMS Components" (Customer Managed Keys, key and IAM policies, key material, grants) and "Key Types" (symmetric 256‑bit AES‑GCM, asymmetric RSA/Elliptic Curve, HMAC). The slide includes a small © Copyright KodeKloud notice in the corner.
Envelope encryption data flow Envelope encryption is a recommended pattern for protecting large datasets while minimizing KMS calls:
  1. Call KMS to generate a data key (returns plaintext data key and a KMS-wrapped CiphertextBlob).
  2. Use the plaintext data key locally to encrypt your data (e.g., AES‑GCM).
  3. Store the encrypted data with the encrypted data key (CiphertextBlob).
  4. To decrypt, call KMS to decrypt the encrypted data key, then use the resulting plaintext key to decrypt the data.
Benefits: fewer KMS API calls, better performance, and a clear key hierarchy for rotation and auditing.
A slide titled "AWS KMS Fundamentals" illustrating the data flow for envelope encryption. It shows plaintext data → generate data key (by KMS) → encrypt data (using data key) → store encrypted data plus encrypted data key.
Customer managed key lifecycle CMKs progress through state transitions—common states are Enabled, Disabled, and Pending Deletion. You can schedule deletion with a configurable waiting period. Use aliases (for example, alias/my-key) to abstract key identifiers from applications and simplify rotation.
A flowchart titled "Customer Managed Keys (CMKs)" showing key lifecycle states: Enabled and Disabled with actions "Enable Key" and "Disable Key." The Disabled state leads downward to "Schedule Deletion" and then "Pending Deletion."
Key policies and access control KMS access control evaluates policies in a strict order:
  1. Evaluate the key policy (KMS resource policy) first.
  2. If the key policy allows the principal, evaluate grants attached to the CMK (temporary scoped permissions).
  3. If neither key policy nor grants allow the action, evaluate the principal’s IAM policies — but this is only effective when the key policy explicitly permits IAM principals to use the key.
  4. Access is granted only if the combined evaluation permits it; otherwise access is denied.
Grants are useful for temporary access or delegated operations (for example, allowing another service or principal to use a key for a limited time).
A flowchart titled "Key Policies and Access Control" that diagrams the decision process for handling an access request. It shows steps like evaluating key policy, checking grants and IAM policy, and ends with either "Access Granted" or "Access Denied."
Key policies act as the primary gate for CMK operations. Ensure your key policy explicitly allows the IAM principals you intend to use; otherwise IAM policies alone will not grant access.
Example key policy (JSON) This example shows administrative privileges for a specific user and limited use permissions for a role, including an encryption context condition.
Note the actions: kms:Encrypt, kms:Decrypt, kms:GenerateDataKey — these align with envelope encryption workflows. Implementation patterns Common ways to implement envelope encryption with KMS:
  • Direct KMS API calls (e.g., GenerateDataKey, Decrypt)
  • AWS Encryption SDK (higher-level, multi-language abstractions)
  • Service-specific integrations (SSE‑KMS for S3, RDS encryption, Secrets Manager, etc.)
A presentation slide titled "Envelope Encryption" that lists three implementation patterns with numbered colored icons: 01 Direct KMS API, 02 AWS Encryption SDK, and 03 Service-specific (S3, RDS, etc.).
Example: Python envelope encryption using a data key (boto3) This example demonstrates generating a data key using KMS, encrypting data locally with AES‑GCM, and outputting base64-encoded values for safe storage or logging.
Service integrations KMS integrates with storage, compute, database, and application services. Many AWS services offer a simple configuration option to use KMS for encryption at rest. Common service integrations:
A diagram titled "Service Integration With KMS" showing an AWS KMS icon in the center. Arrows connect KMS to Storage, Compute, Database and Application service boxes listing examples like S3, EBS, EFS, EC2, Lambda, RDS, DynamoDB, Redshift, SQS and Secrets Manager.
CloudFormation examples (YAML) Below are illustrative CloudFormation snippets showing common property names that reference KMS keys (KmsKeyId, KmsMasterKeyId, KmsDataKeyReusePeriodSeconds). These examples are for learning resource references and patterns — templates may vary in real deployments.
Key rotation strategies Two common rotation approaches:
  • Automatic rotation (supported for symmetric CMKs): rotates key material within the same CMK on a schedule. Low operational overhead.
  • Manual rotation with aliases: create a new CMK and repoint an alias (e.g., alias/my-key) to the new CMK. Offers more control and clearer audit of CMK changes.
Best practices:
  • Use aliases in applications to avoid code/config changes during rotation.
  • For envelope encryption, securely zero plaintext data key material from memory as soon as it’s no longer needed.
  • Test rotation and decryption paths in staging before deploying to production.
A presentation slide titled "Key Rotation Strategies" showing a side-by-side comparison table of Automatic Rotation versus Manual Rotation. It lists aspects like frequency, application impact, previous key versions, key material management, data re-encryption, alias usage, and operational complexity.
Scheduling deletion of a CMK can cause irreversible loss of access to any data encrypted with it after the deletion completes. Use a conservative waiting period and confirm affected resources before scheduling key deletion.
Summary and recommendations
  • KMS is AWS’s centralized key management service; use CMKs when you require control over key material, policy, and cross-account use.
  • Prefer envelope encryption for large-data encryption: it reduces KMS API usage and improves performance.
  • Design key policies carefully — they are evaluated before IAM policies and are the primary gate for CMK operations.
  • Use aliases to minimize application impact during key rotation and to simplify operational management.
  • Leverage service integrations (S3, RDS, Secrets Manager, SQS, etc.) when possible for simpler encryption-at-rest configurations.
Links and references

Watch Video