KMS, encryption at rest & in transit, Secrets Manager
Choose the right key and secret management for each data store.
By Invicly Tech, , in AWS Solutions Architect – Associate. About 13 minutes to read.
In short
AWS KMS manages encryption keys and integrates with S3, EBS, RDS and most data services. Services use envelope encryption: a data key encrypts your data and a KMS key encrypts the data key. ACM provides TLS certificates for encryption in transit, and Secrets Manager stores and rotates credentials.
Think of it like this: Envelope encryption locks data in a box, then locks the box's key in a vault.
Explained simply
Encryption scrambles data so only someone with the right key can read it. In AWS you meet it in two places. At rest means data sitting on disk: files in S3, EBS volumes, database storage. In transit means data moving over a network, protected by TLS, the same technology behind the padlock in your browser.
Keys are the hard part. If you lose them, the data is gone. If someone steals them, encryption is pointless. AWS KMS (Key Management Service) keeps keys inside hardware security modules, devices built so keys cannot be pulled out. Services ask KMS to use a key; they never see the key itself.
Most AWS services make this a checkbox. S3 already encrypts every new object. EBS and RDS encrypt when you tick the box at creation. Your real decisions are which key to use, who may use it, and how you prove it was used correctly.
Passwords and API tokens need care too. Do not put them in code or plain environment files. AWS Secrets Manager stores them encrypted, hands them to apps that are allowed to read them, and can change database passwords automatically on a schedule.
Press Play on a diagram to walk through it one step at a time.
- Service or app to AWS KMS: GenerateDataKey with KMS key1GenerateDataKey with KMS key
- AWS KMS to Service or app: Plaintext and encrypted data key2Plaintext and encrypted data key
- 3Encrypt data, discard plaintext keyService or app to Service or app: Encrypt data, discard plaintext key
- Service or app to Storage: Store ciphertext and encrypted key4Store ciphertext and encrypted key
- Service or app to AWS KMS: Later: Decrypt the data key5Later: Decrypt the data key
- AWS KMS to Service or app: Plaintext key if allowed6Plaintext key if allowed
- Created by a service, e.g. aws/s3
- Rotates yearly automatically
- Cannot edit key policy
- No monthly key fee
- You create and control it
- Custom key policy and grants
- Optional automatic rotation
- Needed for cross-account sharing
- S3
- SSE-S3 by default
- SSE-KMS for control and audit
- Bucket Keys to cut KMS cost
- EBS
- Encryption by default setting
- Snapshots inherit encryption
- RDS and Aurora
- KMS at creation
- TLS forced in parameter group
- DynamoDB
- Always encrypted at rest
- AWS owned, AWS managed or customer key
- Secrets
- Secrets Manager with rotation
- Parameter Store SecureString
In depth
Inside KMS
A KMS key is a logical key: an ID, a key policy, and key material stored in FIPS-validated hardware security modules. Plaintext key material never leaves KMS. You can call Encrypt directly only on small data, up to 4 KB, which is why services use envelope encryption for anything bigger.
Every KMS key must have a key policy. The default key policy gives the account itself full access, which lets IAM policies in that account grant key use. Without that statement, IAM policies alone cannot grant access. Grants give temporary, narrow permissions; EBS uses them to let an instance decrypt its volume.
Rotation creates new key material but keeps the old material, so old data still decrypts and the key ID stays the same. AWS managed keys rotate every year. For customer managed keys, rotation is optional, with a period from 90 to 2,560 days, and you can also rotate on demand. Deletion has a 7 to 30 day waiting period, since a deleted key makes its data unreadable forever.
- Symmetric AES-256 keys by default; RSA, ECC and HMAC also available
- Direct Encrypt is limited to 4 KB of data
- Multi-Region keys share key material across Regions
- Disable a key instead of deleting it if unsure
S3 encryption choices
Since January 2023, S3 encrypts every new object with SSE-S3 (keys managed by S3) at no extra cost. You can change the bucket default to SSE-KMS, which uses a KMS key. SSE-KMS adds two things: a separate permission (readers need kms:Decrypt as well as s3:GetObject), and a CloudTrail record of every key use. DSSE-KMS applies two layers of encryption for strict compliance rules. SSE-C uses a key you send with each request, and S3 never stores it.
SSE-KMS calls KMS for every object, which costs money and counts against KMS request quotas. Turn on S3 Bucket Keys: S3 then gets a short-lived bucket-level key from KMS and reuses it, cutting KMS requests by up to 99 percent.
For cross-account sharing, use a customer managed key. The AWS managed key aws/s3 has a key policy you cannot change, so other accounts can never be allowed to use it.
- Default for new objects
- Keys fully managed by S3
- No extra permission or cost
- No per-key audit trail
- AWS managed or customer managed key
- Needs kms:Decrypt to read
- Key use logged in CloudTrail
- Use Bucket Keys to cut cost
- You supply the key per request
- S3 never stores the key
- Lose the key, lose the data
- HTTPS required
EBS and RDS: encrypt at creation
EBS and RDS encryption is set when a volume or database is created and cannot be switched on later in place. For EBS, turn on encryption by default, a per-Region account setting; every new volume and snapshot copy is then encrypted. Snapshots of an encrypted volume are encrypted, and volumes made from them are too.
To encrypt existing data you go through a snapshot. For EBS, snapshot the volume, then create a new volume from that snapshot with encryption enabled (or copy the snapshot with encryption), and swap volumes. For RDS, snapshot the instance, copy the snapshot with encryption and a KMS key, and restore a new instance from the copy, then point the app at it.
Read replicas use the same encryption state as their source. Copying an encrypted snapshot to another Region needs a KMS key in the destination Region. Sharing an encrypted snapshot with another account requires a customer managed key whose policy lets that account use it.
- 1Snapshot
Take a manual snapshot of the instance.
- 2Copy encrypted
Copy it with a KMS key selected.
- 3Restore
New instance from the encrypted copy.
- 4Cut over
Point the app at the new endpoint.
- 5Retire old
Delete the unencrypted instance.
TLS in transit with ACM
AWS Certificate Manager issues public TLS certificates for free and installs them on integrated services: Application and Network Load Balancers, CloudFront, API Gateway and others. With DNS validation, you add one CNAME record and ACM renews the certificate automatically as long as that record stays. Email validation needs a person to click a link at each renewal, so prefer DNS.
Certificates are Regional. A load balancer needs a certificate in its own Region, while CloudFront always needs one from us-east-1. For internal services, AWS Private CA issues private certificates.
Turning on TLS is only half the job; you also have to require it. Redirect HTTP to HTTPS on the load balancer listener. Deny S3 requests where aws:SecureTransport is false. Require TLS on databases with rds.force_ssl for PostgreSQL or require_secure_transport for MySQL, set in a parameter group.
- ALB: HTTPS listener plus HTTP-to-HTTPS redirect
- CloudFront certificates must be in us-east-1
- S3: deny when aws:SecureTransport is false
- RDS: force TLS through the parameter group
Secrets Manager and Parameter Store
Secrets Manager stores secrets encrypted with KMS, controls access with IAM and resource policies, replicates secrets to other Regions, and rotates them. Rotation runs a Lambda function through four steps: create a new secret version, set it in the database, test it, then mark it current. Versions carry labels AWSCURRENT, AWSPENDING and AWSPREVIOUS, so apps always fetch the current one. For RDS and Aurora master passwords, managed rotation needs no Lambda at all: create the database with the manage-master-user-password option.
Systems Manager Parameter Store is a cheaper option for configuration. Standard parameters are free, and SecureString parameters are encrypted with KMS. It has no built-in rotation.
The exam rule: if a scenario says "rotate database credentials automatically", pick Secrets Manager. If it just needs to store configuration values or a few secrets cheaply, Parameter Store is fine.
- 1createSecret
New password stored as AWSPENDING.
- 2setSecret
Password changed in the database.
- 3testSecret
Log in with the new password.
- 4finishSecret
AWSPENDING becomes AWSCURRENT.
- Back to step 1
Learn it in 5 short steps
About 50m each. Track them with a timer in your plan.
- 1Compare AWS managed and customer managed keys~50m
- 2Explain envelope encryption~50m
- 3Encrypt S3, EBS and RDS at rest~50m
- 4Enforce TLS in transit with ACM~50m
- 5Store and rotate secrets in Secrets Manager~50m
Key points
- Use a customer managed key when you need key policy control, audit or cross-account use.
- S3 encrypts new objects with SSE-S3 by default; choose SSE-KMS for key control and audit.
- Encrypted EBS and RDS must be enabled at creation; copy snapshots to encrypt existing data.
- ACM public certificates are free and auto-renew on ALB, CloudFront and API Gateway.
- Secrets Manager rotates database credentials automatically with a Lambda function.
Key terms
Tap a card to flip it. 0/6 known
Examples
# Create a customer managed key
aws kms create-key --description "app data key"
# Upload an object encrypted with that key
aws s3 cp report.csv s3://my-bucket/ \
--sse aws:kms --sse-kms-key-id alias/app-data
# Store a database password
aws secretsmanager create-secret --name prod/db \
--secret-string "{\"password\":\"S3cret!\"}"Locking down a finance bucket
Finance reports must use a customer managed key and only travel over TLS. Step 1: set the bucket default encryption to SSE-KMS with the key alias and Bucket Keys on, so uploads are encrypted even if the client sends no encryption header. Step 2: add a bucket policy that denies any request where aws:SecureTransport is false. Step 3: give readers both s3:GetObject and kms:Decrypt on the key. A common trap: a policy that denies uploads missing a specific key ID header also blocks clients relying on the default, so prefer default encryption plus a TLS deny.
aws s3api put-bucket-encryption --bucket fin-reports \
--server-side-encryption-configuration '{"Rules":[{
"ApplyServerSideEncryptionByDefault":{
"SSEAlgorithm":"aws:kms","KMSMasterKeyID":"alias/fin-data"},
"BucketKeyEnabled":true}]}'
aws s3api put-bucket-policy --bucket fin-reports --policy '{
"Version":"2012-10-17","Statement":[{"Sid":"TLSOnly",
"Effect":"Deny","Principal":"*","Action":"s3:*",
"Resource":["arn:aws:s3:::fin-reports","arn:aws:s3:::fin-reports/*"],
"Condition":{"Bool":{"aws:SecureTransport":"false"}}}]}'A new database with no password in code
Step 1: create the RDS instance with storage encryption, your KMS key, and a master password managed by Secrets Manager, so no human ever types or sees it. Step 2: RDS creates the secret and rotates it automatically, every 7 days by default. Step 3: look up the secret ARN from the instance. Step 4: give the app's IAM role secretsmanager:GetSecretValue on that ARN only. Step 5: the app fetches the secret at start-up and caches it, refreshing on login failure so a rotation never breaks it.
aws rds create-db-instance --db-instance-identifier orders-db \
--engine postgres --db-instance-class db.t4g.micro \
--allocated-storage 20 --master-username appadmin \
--manage-master-user-password \
--storage-encrypted --kms-key-id alias/app-data \
--no-publicly-accessible
aws rds describe-db-instances --db-instance-identifier orders-db \
--query "DBInstances[0].MasterUserSecret.SecretArn" --output textQuick reference
- Direct KMS Encrypt handles at most 4 KB; bigger data uses envelope encryption
- Customer managed key rotation: optional, 90 to 2,560 days; AWS managed keys rotate yearly
- Key deletion waits 7 to 30 days; disable the key if you are unsure
- SSE-KMS readers need kms:Decrypt too; turn on Bucket Keys to cut KMS requests
- Share encrypted snapshots or objects cross-account only with a customer managed key
- Encrypt existing EBS or RDS data by going through a snapshot copy
- ACM certificates for CloudFront must be in us-east-1; DNS validation auto-renews
- Automatic credential rotation means Secrets Manager; cheap config storage means Parameter Store
Common mistakes
- Expecting to toggle encryption on an existing unencrypted RDS instance in place.
- Forgetting KMS request quotas and costs with very high SSE-KMS traffic; use S3 Bucket Keys.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Create a customer managed key with the alias alias/lab, encrypt a small text file with it, and decrypt it again.
- Exercise 2medium
Turn on EBS encryption by default in your lab Region using the alias/lab key, and confirm the setting.
- Exercise 3hard
Share an encrypted EBS snapshot with account 222233334444 so they can make their own copy.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is S3 data encrypted by default?
- Yes. Since January 2023, every new object is encrypted with SSE-S3 unless you choose another option. Choose SSE-KMS when you need key control or an audit trail.
- What is the difference between KMS and CloudHSM?
- KMS is a shared, fully managed key service integrated with most AWS services. CloudHSM gives you dedicated single-tenant HSMs where you alone manage users and keys, for strict compliance needs.
- Does encryption slow down EBS or RDS?
- The impact is negligible for most workloads, because encryption is handled by the underlying Nitro hardware and storage layer.
- Secrets Manager or Parameter Store?
- Secrets Manager when you need automatic rotation, cross-Region replication or cross-account sharing. Parameter Store for configuration values and simple secrets at low or no cost.