Sub topic 3
Encrypting data in AWS services with KMS
Assume you understand IAM roles and policies, the AWS CLI, and the difference between plaintext and ciphertext. AWS services use AWS Key Management Service (KMS) keys to encrypt data at rest. The service performs encryption on your behalf, while KMS controls access to the key.
Encrypting data in AWS services
For example, configure an S3 bucket to use a customer managed KMS key:
aws s3api put-bucket-encryption \
--bucket my-example-bucket \
--server-side-encryption-configuration '{
"Rules": [{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms",
"KMSMasterKeyID": "alias/tutorial-key"
},
"BucketKeyEnabled": true
}]
}'The role that uploads or downloads objects needs S3 permissions and KMS permissions such as kms:Encrypt and kms:Decrypt. The bucket policy and KMS key policy must allow the intended access.
Rotating keys
Automatic rotation changes the backing key material while preserving the same key ID and alias. Existing ciphertext remains decryptable. Enable it with:
aws kms enable-key-rotation --key-id alias/tutorial-key
aws kms get-key-rotation-status --key-id alias/tutorial-keyRotation does not update permissions or re-encrypt every existing object.
Disabling and deleting keys safely
Disabling a key immediately prevents most cryptographic operations. Schedule deletion instead of deleting immediately. KMS requires a waiting period from 7 to 30 days:
aws kms schedule-key-deletion \
--key-id alias/tutorial-key \
--pending-window-in-days 30During the waiting period, cancel deletion if dependent data still needs the key.
Auditing and operating at scale
CloudTrail records KMS API calls, including the principal, operation, key, and encryption context. Review these events for unexpected use.
KMS has request quotas, and customer managed keys incur charges. S3 Bucket Keys reduce KMS request volume and cost by allowing S3 to reuse a short-lived bucket-level key for objects.
| Feature | Main benefit |
|---|---|
| S3 Bucket Key | Fewer KMS requests for S3 objects |
Multi-Region keys share key material across selected Regions. Use them when encrypted data must move between Regions with compatible key identity. They do not automatically replicate data or remove regional availability concerns.
Imported key material gives you control over the material's origin and lifecycle. Custom key stores place key material in CloudHSM or an external key manager. These options add operational responsibility and failure modes, so use them only for specific compliance or control requirements.
Exercise
What should you check before scheduling a KMS key for deletion?
Show answer
Check all services, backups, ciphertext, IAM permissions, and recovery procedures that depend on the key.