AWS — KMS
What is KMS?
Managed service for creating and controlling encryption keys.
Create key
aws kms create-key \
--description "My encryption key" \
--tags TagKey=Name,TagValue=my-key
Encrypt data
aws kms encrypt \
--key-id alias/my-key \
--plaintext "Hello World" \
--output text \
--query CiphertextBlob | base64 --decode > encrypted.bin
Decrypt data
aws kms decrypt \
--ciphertext-blob fileb://encrypted.bin \
--output text \
--query Plaintext | base64 --decode
Generate data key
import boto3
kms = boto3.client('kms')
response = kms.generate_data_key(
KeyId='alias/my-key',
KeyPairSpec='AES_256'
)
# Use response['Plaintext'] for encryption
# Store response['CiphertextBlob'] for decryption
Key policies
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::123456789:root"},
"Action": "kms:*",
"Resource": "*"
}
]
}
Best practices
- Use least privilege
- Enable key rotation
- Use aliases for management
- Monitor with CloudTrail
Mini Practice
- Create a KMS key
- Encrypt and decrypt data
- Generate data keys
- Set up key policies
Up Next
Continue with Certificate Manager - SSL/TLS certificates.
Related Topics
Frequently Asked Questions about KMS
What is KMS in AWS?
KMS is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn KMS?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn KMS.
Why is KMS important in AWS?
KMS is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.