📖 Scenario: You are setting up a secure environment in AWS. You need to create a KMS (Key Management Service) key to encrypt your sensitive data safely.
🎯 Goal: Build an AWS CloudFormation template that creates a KMS key with a description and enables key rotation.
📋 What You'll Learn
Create a KMS key resource with the exact logical ID MyKmsKey
Set the Description property to "My first KMS key"
Enable automatic key rotation by setting EnableKeyRotation to true
Add a KeyPolicy that allows the root user full access
💡 Why This Matters
🌍 Real World
KMS keys are used to encrypt sensitive data in AWS services like S3, EBS, and RDS. Managing keys securely is critical for protecting data.
💼 Career
Cloud engineers and security specialists often create and manage KMS keys to enforce encryption policies and comply with security standards.
Progress0 / 4 steps
1
Create the KMS key resource
Create a resource called MyKmsKey of type AWS::KMS::Key in the Resources section of the CloudFormation template.
AWS
Hint
Use the Resources section to define MyKmsKey with the correct type.
2
Add a description to the KMS key
Inside the MyKmsKey resource, add a Properties section with a Description set to "My first KMS key".
AWS
Hint
Properties hold configuration details like Description.
3
Enable automatic key rotation
Inside the Properties of MyKmsKey, add EnableKeyRotation set to true to enable automatic key rotation.
AWS
Hint
EnableKeyRotation is a boolean property inside Properties.
4
Add a key policy allowing root user full access
Inside the Properties of MyKmsKey, add a KeyPolicy that allows the root user full access. Use the exact policy structure with "Effect": "Allow", "Principal": { "AWS": { "Fn::Sub": "arn:aws:iam::${AWS::AccountId}:root" } }, and "Action": "kms:*" on "Resource": "*".
AWS
Hint
The KeyPolicy is a JSON object with Version and Statement array. The Statement must allow root user full access.
Practice
(1/5)
1. What is the main purpose of AWS KMS (Key Management Service)?
easy
A. To create and manage encryption keys for data protection
B. To store large files securely
C. To monitor network traffic
D. To manage user access permissions
Solution
Step 1: Understand the role of KMS
AWS KMS is designed to create and manage cryptographic keys used to encrypt and decrypt data.
Step 2: Compare with other options
Options B, C, and D describe other AWS services or functions unrelated to key management.
Final Answer:
To create and manage encryption keys for data protection -> Option A
Quick Check:
KMS purpose = encryption key management [OK]
Hint: KMS is about keys, not files or users [OK]
Common Mistakes:
Confusing KMS with storage services
Thinking KMS manages user permissions
Assuming KMS monitors network traffic
2. Which of the following is the correct way to enable automatic yearly key rotation for a KMS key using AWS CLI?
easy
A. aws kms rotate-key --key-id
B. aws kms update-key --key-id --rotation on
C. aws kms set-key-rotation --key-id --enable true
D. aws kms enable-key-rotation --key-id
Solution
Step 1: Recall AWS CLI command for key rotation
The correct command to enable automatic yearly rotation is 'aws kms enable-key-rotation --key-id '.
Step 2: Check other options for correctness
Options A, C, and D are not valid AWS CLI commands for enabling key rotation.
Final Answer:
aws kms enable-key-rotation --key-id <key-id> -> Option D