Secure architectures · 13 min
Encryption at rest with AWS KMS
In this lesson you will learn how envelope encryption works, what types of keys AWS KMS has and when a customer managed key is the right choice, and how a key is controlled, shared, rotated and deleted.
Encrypting data means turning it into text that nobody can read without the right key, and decrypting it means using that key to read it again. A key is a secret code, a long series of numbers, and whoever has it can read everything that was encrypted with it. For example, if an online store keeps its customer list encrypted and someone steals the file, they only see meaningless characters; but if they also steal the key, they can read all of it.
AWS Key Management Service (AWS KMS) is the service that creates and stores the keys used to encrypt data at rest, that is, the data stored in S3 (files), in EBS (the servers' disks) or in a database. Almost everything in AWS is already encrypted at rest in one way or another: since January 5, 2023, for example, Amazon S3 encrypts every new object with SSE-S3, at no cost and without you doing anything. That is why the Solutions Architect exam mostly asks who controls the key, who can use it and how each use is logged.
What is a KMS key?
A KMS key is created, used and deleted inside KMS. It is protected by hardware security modules (HSMs), which are devices built to keep keys without letting them be copied, validated under FIPS 140-3 Level 3, a United States government standard for that kind of device. Also, the key never leaves KMS unencrypted, so to use it you have to call KMS, that is, send it the data and ask it to encrypt or decrypt it. For example, the store's program never sees the KMS key: it only asks KMS to do the work and gets the result back.
That way of working has a size limit. The KMS Encrypt operation encrypts at most 4,096 bytes, which is enough for a password but not for a 2 GB file, and that is why large data is encrypted with another technique, envelope encryption.
How does envelope encryption work?
Envelope encryption uses two keys: a data key that encrypts the data and the KMS key that encrypts the data key. It is called that because the encrypted data and its encrypted key travel together, like a letter inside a sealed envelope. For example, the store encrypts each backup of its database with a different data key, and only KMS can open those keys. Encrypting with this method takes four steps.

First, the application asks KMS for a data key with GenerateDataKey, and KMS returns two copies of that key: one in plaintext, that is, unencrypted, to use right away and another encrypted with the KMS key. Next, the application encrypts the data itself, outside KMS, with the plaintext copy. When it finishes, it stores the encrypted data and the encrypted data key together, which form the envelope, and erases the plaintext key from memory.
To decrypt, the application sends KMS only the encrypted data key. KMS checks whether the caller has the kms:Decrypt permission on the KMS key and, if it does, returns the plaintext data key so the application can decrypt the data. This way, the large data never travels to KMS. For example, to open one of the store's backups, the program sends KMS only the small encrypted key attached to the backup, gets the open key back and decrypts the backup itself.
S3 encryption with AWS KMS
Amazon S3 is the AWS service for storing files, which are organized in buckets. SSE means server-side encryption: S3 encrypts the file when it stores it and decrypts it when it hands it back. S3 has several options for encryption at rest, among them these three:
- SSE-S3, which is the default option and encrypts with AES-256, a widely used encryption method, at no cost.
- SSE-KMS, which encrypts with a KMS key and uses envelope encryption internally.
- SSE-C, which uses a key you provide and have to send with every request, and which since April 2026 is disabled by default on new buckets.
Because SSE-KMS uses envelope encryption, to read an object encrypted with that option an identity needs two permissions: s3:GetObject on the bucket and kms:Decrypt on the key. If it lacks the second one, KMS doesn't decrypt the data key on behalf of that identity, and the read fails even though it has permission on the bucket. For example, if the store's site role can read the invoices bucket but doesn't have kms:Decrypt on the key, the invoices don't open.
True or false?
0 of 3To encrypt a 2 GB file, the application sends the whole file to KMS with the Encrypt operation.
A role with s3:GetObject but no permissions on the key can't read an object encrypted with SSE-KMS.
The KMS key travels encrypted to the application so it can decrypt the data.
Types of AWS KMS keys

AWS KMS has three types of keys, which differ in who creates them and how much you can control them:
- AWS owned keys, which live in a service account, can't be viewed or audited and have no cost.
- AWS managed keys, which live in your account with aliases such as
aws/s3oraws/rds, are created by the service, rotate every year and have no monthly fee, but whose policy can't be changed and which can't be rotated by hand or deleted. - Customer managed keys, which you create and where you decide everything, from the policy and rotation to disabling or deleting them.
AWS managed keys and customer managed keys live in your account, so every use of them is logged in AWS CloudTrail, the service that records every action taken in the account, with who took it and when. That difference matters when a requirement calls for auditing who used a key, because an AWS owned key can't be audited. For example, if the store needs to know which employee opened a customer's invoices, it has to encrypt them with a key that lives in its account.
The three types also differ in cost. A customer managed key costs 1 USD per month, plus requests, and KMS gives you 20,000 free requests per month. To lower that cost in a bucket with SSE-KMS there are S3 Bucket Keys, which according to AWS reduce requests to KMS by up to 99% without you changing the application. For example, if the store keeps millions of product photos with SSE-KMS, each photo would be a request to KMS, and with S3 Bucket Keys S3 makes far fewer.
Who can use a key?
Each KMS key has exactly one key policy, which is a resource policy: a document attached to the key that says who can use it and for what. If that policy doesn't give permissions to an identity, the identity has none on the key, even if it is the root user or whoever created the key. That policy can give permission in three ways.

In the first way, the key policy names the role. In the second, the key policy enables the account's IAM policies and an IAM policy on the role allows it. In the third, a grant gives temporary usage permissions. In all three ways, the key policy is the one that has the final say. For example, the store writes in its key's policy that the site's role can encrypt and decrypt, and that only the security team can change that policy.
Across accounts two pieces are needed: the key policy in the owning account allows the other account, and an IAM policy in the other account allows using the key. With an AWS managed key that can't be done, because its policy can't be changed. For example, RDS, the managed database service, doesn't let you share a snapshot encrypted with the account's default key, and the way out is to copy the snapshot with a customer managed key and share that copy.
Which key do you use?
A company has to share encrypted Amazon RDS snapshots with a partner's account, and the audit team asks to control exactly who can decrypt them. Which key are the shared snapshots encrypted with?
Rotating and deleting a key
Rotating a key changes only its cryptographic material, which is the secret code that actually does the encrypting. The ID, the ARN and the policy stay the same, and KMS keeps the previous material to decrypt what was already encrypted, so you don't have to change any code. However, rotation doesn't re-encrypt existing data or rotate the data keys. For example, when the store's key rotates, last year's invoices still open with the previous material, and the new ones are encrypted with the new material.
For customer managed keys, automatic rotation is optional, with a period of 90 to 2,560 days (365 by default), and you can also rotate them on demand. AWS managed keys, on the other hand, rotate every year, and that period can't be changed.
Deleting a key can't be undone, because whatever was encrypted with it can no longer be read. That is why KMS makes you wait 7 to 30 days (30 by default) before deleting it, and during that wait you can cancel the deletion. For example, if someone at the store schedules the deletion of the invoices key by mistake, the team has those days to notice and cancel it before losing every invoice.
In a new experience account
In a new experience account, KMS and S3 and EBS encryption work on the free plan. Multi-Region keys, which are copies of the same key in several AWS Regions, don't work, because no cross-Region feature is available, and AWS CloudHSM, which rents you an HSM of your own, isn't available either. For example, in that account you can create a customer managed key, encrypt a bucket with it and see every use in CloudTrail.
How does it show up on the exam?
Questions on encryption at rest usually ask for the key option that meets a control or cost requirement, and these phrases in the question point to the answer:
| If the question says | The answer |
|---|---|
| "Control who uses the key", "share encrypted data with another account" or "choose the rotation period" | A customer managed key |
| "Least effort", with no other requirement | The AWS managed key |
| "Reduce the KMS cost in a bucket with SSE-KMS without changing the application" | S3 Bucket Keys |
| "Rotate every 180 days" | A customer managed key with that rotation period |
For example, if the question says the store wants to encrypt its photos with the least effort and asks for nothing else, the AWS managed key is enough; if it also asks to share them with another account, a customer managed key is needed.
Review question
An internal policy requires rotating the keys that encrypt the data in an S3 bucket every 180 days and logging every use of the key in CloudTrail. Today the bucket uses SSE-S3. Which change meets both requirements?
Next
- AWS Key Management Service, in the AWS documentation.
- The Solutions Architect practice exams at /examenes.