AWS Builder Center
How to Implement AWS KMS: Encryption at Rest Explained (2026 Guide)

How to Implement AWS KMS: Encryption at Rest Explained (2026 Guide)

Learn AWS KMS encryption at rest with S3, IAM and key policies, Terraform examples, encryption enforcement, pricing, CloudTrail, and troubleshooting.

How to Implement AWS KMS: Encryption at Rest Explained

Your S3 bucket is encrypted. But who controls the key?
That's the question many cloud engineers forget to ask.
Imagine this.
Your company stores customer information, financial documents, backups, and sensitive application data in Amazon S3.
Encryption is enabled.
Your security dashboard looks healthy.
Everything appears protected.
Then someone asks:
"What happens if an unauthorized identity can access the bucket but cannot use the encryption key?"
Now we're talking about security architecture.
Because encryption at rest is only one part of protecting cloud data.
The next part is controlling who can decrypt it.
That's where AWS Key Management Service (AWS KMS) comes in.
In this practical guide, you'll learn how to implement AWS KMS encryption at rest using Amazon S3, secure KMS keys with IAM and key policies, enforce encryption, troubleshoot errors, monitor operations, and automate the setup with Terraform.
We'll also cover real pricing, cleanup, and when SSE-KMS isn't the right choice.
Let's build it.

Illustration showing an encrypted Amazon S3 bucket connected to a separately controlled AWS KMS key.


1. What Is Encryption at Rest?

Encryption at rest protects data while it's stored.
That includes:
  • Objects in Amazon S3.
  • Database records in Amazon RDS.
  • Volumes attached to EC2 instances through Amazon EBS.
  • Backups and snapshots.
Encryption turns readable information into ciphertext.
The encrypted content becomes readable again through an authorized decryption process.
Think of the workflow like this:
 Plaintext → Encryption + Key → Ciphertext 
 Ciphertext → Decryption + Key → Plaintext 
Without the appropriate key material, encrypted data should remain unintelligible.
But encryption alone doesn't mean your data is inaccessible to attackers.
If an attacker obtains valid access to both an S3 object and its associated encryption key, the storage service may still return plaintext.
Encryption protects the data. Access control protects who can retrieve it.
You need both.

2. What Is AWS KMS?

AWS Key Management Service is a managed service for creating, controlling, and using cryptographic keys.
Instead of maintaining your own key-management infrastructure, you can use AWS KMS to integrate cryptographic controls with services such as S3, EBS, RDS, and other AWS workloads.
AWS KMS helps you:
  • Create and manage encryption keys.
  • Control who can use keys through key policies, IAM, and grants.
  • Rotate supported key material.
  • Monitor key activity through AWS CloudTrail.
  • Restrict key usage to specific services or workloads.
Here's the difference that matters.
Having permission to access an S3 object doesn't automatically mean having permission to use its KMS key.
For example:
An application may have  s3:GetObject .
But without the necessary  kms:Decrypt  authorization, reading its SSE-KMS encrypted content can fail.
Two authorization boundaries. One protected object.

Two-gate AWS security diagram showing how access to an SSE-KMS encrypted Amazon S3 object requires b


3. SSE-S3 vs. SSE-KMS vs. DSSE-KMS

Amazon S3 already encrypts new object uploads by default.
Since January 5, 2023, it has applied server-side encryption with Amazon S3 managed keys (SSE-S3) unless a different encryption configuration applies.
So why use AWS KMS?
Because different workloads need different controls.
Encryption type
Key management
Best fit
SSE-S3
Managed by S3
Simple encryption without additional KMS management
SSE-KMS
Uses AWS KMS keys
Custom key controls and KMS audit visibility
DSSE-KMS
Two independent encryption layers using AWS KMS
Workloads requiring dual-layer server-side encryption
For SSE-KMS, you can use an AWS managed key or a customer managed KMS key.
Customer managed keys let you customize permissions, control rotation, manage lifecycle actions, and implement more granular access requirements.
When should you choose SSE-KMS?
When you have a specific requirement for key-level authorization, auditing, or lifecycle control.
Don't choose it just because it sounds more secure.
Choose it because your workload needs those controls.

4. How AWS KMS Envelope Encryption Works

Here's a concept every cloud engineer should understand:
Envelope encryption.
AWS KMS doesn't need to encrypt every S3 object directly with the KMS key.
Instead, S3 uses data keys.
The process typically works like this:
  1. A client uploads an object to Amazon S3.
  1. S3 requests a data key from AWS KMS using  GenerateDataKey .
  1. AWS KMS returns a plaintext data key and an encrypted copy of that key.
  1. S3 encrypts the object using the plaintext data key.
  1. S3 discards the plaintext data key after use and retains the encrypted data key with the object.
  1. During an authorized download, S3 obtains the data key needed to decrypt the object, normally through a KMS  Decrypt  operation.
The underlying KMS key material remains protected within AWS KMS.
In simple terms:
Data keys encrypt objects. KMS keys protect data keys.
This allows S3 to efficiently encrypt large volumes of information while maintaining centralized control over key usage.
S3 Bucket Keys modify this workflow to reduce the number of requests S3 makes to AWS KMS.

AWS S3 envelope encryption sequence diagram showing the Client, Amazon S3, and AWS KMS. During uploa


5. Implement AWS KMS Encryption for Amazon S3

Now let's configure SSE-KMS using the AWS CLI.
We'll use an existing general-purpose S3 bucket.

Prerequisites

You'll need an AWS account, AWS CLI v2, an existing S3 bucket, and sufficient IAM permissions to create KMS keys and manage bucket encryption.
For the examples, use  us-east-1 .
Test in a dedicated nonproduction environment before touching production infrastructure.

Step 1: Configure your environment

export AWS_REGION="us-east-1"
export BUCKET="your-unique-bucket-name"

export ACCOUNT_ID=$(aws sts \
get-caller-identity \
--query Account \
--output text)
Confirm the bucket Region:
aws s3api get-bucket-location \
--bucket "$BUCKET"
The KMS key and S3 bucket must be in the same AWS Region.

Step 2: Create a customer managed KMS key

export KMS_KEY_ARN=$(aws kms create-key \
--region "$AWS_REGION" \
--description "S3 application encryption key" \
--key-usage ENCRYPT_DECRYPT \
--key-spec SYMMETRIC_DEFAULT \
--query 'KeyMetadata.Arn' \
--output text)
Check the ARN:
echo "$KMS_KEY_ARN"
Now you have a symmetric customer managed KMS key.
An important security detail:
When  create-key  is called without an explicit policy, AWS KMS creates a default key policy that enables the AWS account to delegate access using IAM policies.
It does this through the account principal:
 arn:aws:iam::ACCOUNT_ID:root 
This doesn't mean every IAM user automatically receives permission to use the key.
Instead, it enables IAM permissions to take effect.
Without key-policy authorization or delegation, an IAM Allow statement alone might accomplish nothing.

Step 3: Create a key alias

aws kms create-alias \
--alias-name alias/s3-app-data \
--target-key-id "$KMS_KEY_ARN" \
--region "$AWS_REGION"
Aliases make keys easier to identify.
Use the full key ARN in your encryption configuration, especially when cross-account access is involved.

Step 4: Enable automatic rotation

aws kms enable-key-rotation \
--key-id "$KMS_KEY_ARN" \
--region "$AWS_REGION"
The default automatic rotation period for eligible keys is 365 days.
Automatic rotation preserves the KMS key identity while rotating its backing cryptographic material.
Previously encrypted data remains decryptable because AWS KMS retains the necessary earlier key material.
However:
Rotation does not immediately re-encrypt existing S3 objects.
Also remember that rotating customer managed keys can increase monthly key-storage charges.

AWS KMS key rotation diagram showing three versions of cryptographic key material (v1, v2, and v3) a


Step 5: Enable S3 default SSE-KMS encryption

Create  s3-kms-encryption.json :
cat > s3-kms-encryption.json <<EOF
{
"Rules": [
{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms",
"KMSMasterKeyID": "$KMS_KEY_ARN"
},
"BucketKeyEnabled": true
}
]
}
EOF
Apply it:
aws s3api put-bucket-encryption \
--bucket "$BUCKET" \
--region "$AWS_REGION" \
--server-side-encryption-configuration \
file://s3-kms-encryption.json
This sets SSE-KMS as the default encryption configuration for subsequent object writes when another valid encryption option isn't explicitly requested.
We've also enabled S3 Bucket Keys to reduce KMS request traffic.
But there's a critical limitation.
Default encryption is not strict enforcement.
A client can explicitly request an alternative supported encryption configuration unless access policies prevent that behavior.
We'll fix this shortly.

Step 6: Verify the configuration

aws s3api get-bucket-encryption \
--bucket "$BUCKET" \
--region "$AWS_REGION"
Confirm:
  • The algorithm is  aws:kms .
  • The selected key ARN matches your customer managed key.
  • Bucket Keys are enabled.
S3 does not validate the supplied KMS key ID when accepting the default encryption configuration, so a real upload test is still essential.

6. AWS KMS Key Policy: Separate Administrators from Key Users

This is where a basic tutorial becomes a real security implementation.
A KMS key policy controls who may manage or use a particular key.
Let's separate two roles:
Key administrator: Can manage the key lifecycle and policies.
Application key user: Can generate data keys and decrypt data through S3.
We'll also preserve the default account-level IAM delegation statement.
Assume these IAM roles already exist:
  •  KmsKeyAdmins 
  •  AppS3Role 
Set their ARNs:
export ADMIN_ROLE_ARN="arn:aws:iam::$ACCOUNT_ID:role/KmsKeyAdmins"
export APP_ROLE_ARN="arn:aws:iam::$ACCOUNT_ID:role/AppS3Role"
Create  kms-key-policy.json :
cat> kms-key-policy.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnableAccountIAMDelegation",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::$ACCOUNT_ID:root"
},
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "AllowKeyAdministrators",
"Effect": "Allow",
"Principal": {
"AWS": "$ADMIN_ROLE_ARN"
},
"Action": [
"kms:DescribeKey",
"kms:PutKeyPolicy",
"kms:EnableKey",
"kms:DisableKey",
"kms:EnableKeyRotation",
"kms:DisableKeyRotation",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion"
],
"Resource": "*"
},
{
"Sid": "AllowApplicationKeyUsage",
"Effect": "Allow",
"Principal": {
"AWS": "$APP_ROLE_ARN"
},
"Action": [
"kms:GenerateDataKey",
"kms:Decrypt"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:ViaService": "s3.$AWS_REGION.amazonaws.com"
}
}
}
]
}
EOF
Apply the key policy:
aws kms put-key-policy \
--key-id "$KMS_KEY_ARN" \
--policy-name default \
--policy file://kms-key-policy.json \
--region "$AWS_REGION"
Important implementation notes:
  • The administrator's  PutKeyPolicy  permission allows the policy to be changed. Administrators with this power can potentially grant themselves additional key permissions.
  • The root account-principal statement enables IAM delegation. It does not mean every IAM identity gets  kms:*  automatically.
  • The application role is explicitly authorized for two cryptographic operations through S3.
  • The role running  put-key-policy  must retain permission to manage the policy. Don't bypass AWS's policy lockout safety check.
  •  kms:CreateKey  is an account-level key-creation permission, not a management permission on this existing key. Grant it separately through IAM to an appropriate provisioning role.
For stronger separation of duties, use IAM permission boundaries, service control policies where appropriate, role restrictions, and independent approval processes.
Key administrators should manage keys. Applications should use keys. Neither should receive unnecessary privileges.

7. Configure IAM Permissions

Now let's grant the application role the required="true" S3 and KMS permissions.
A typical permission mapping looks like this:
Operation
S3 permission
KMS permission
Upload
 s3:PutObject 
 kms:GenerateDataKey 
Download
 s3:GetObject 
 kms:Decrypt 
Multipart upload
Applicable S3 permissions
 kms:GenerateDataKey ,  kms:Decrypt 
Example IAM policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ObjectAccess",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::YOUR_BUCKET/*"
},
{
"Sid": "KMSKeyUsage",
"Effect": "Allow",
"Action": [
"kms:GenerateDataKey",
"kms:Decrypt"
],
"Resource": "YOUR_KMS_KEY_ARN",
"Condition": {
"StringEquals": {
"kms:ViaService": "s3.us-east-1.amazonaws.com"
}
}
}
]
}
Replace the placeholders and attach this policy to the application's IAM role.

How permission evaluation works

S3 access and KMS access are separate authorization decisions.
An operation must pass the relevant S3 authorization checks and the required="true" KMS authorization checks.
Within KMS, authorization may come from key policies, IAM policies enabled by the key policy, or grants.
These mechanisms don't each need their own Allow for every request. Valid authorization can come through the applicable permitted path.
However, an applicable explicit Deny overrides an Allow.
For example:
  • S3 allows  GetObject .
  • KMS does not authorize  Decrypt .
  • The encrypted object's content remains inaccessible through that request.

AWS permission evaluation flowchart showing how access to an SSE-KMS encrypted Amazon S3 object is a


8. Enforce SSE-KMS with an S3 Bucket Policy

A bucket's default encryption setting does not prevent a caller from requesting another supported encryption configuration.
To require a particular customer managed KMS key, you can add explicit Deny conditions to the bucket policy.
For this tutorial, we'll enforce two rules:
  1. Every  PutObject  request must explicitly specify  aws:kms .
  1. Every upload must explicitly provide the required="true" customer managed KMS key ARN.
Create  s3-kms-enforce.json :
cat> s3-kms-enforce.json <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyMissingEncryptionHeader",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::$BUCKET/*",
"Condition": {
"Null": {
"s3:x-amz-server-side-encryption": "true"
}
}
},
{
"Sid": "DenyWrongEncryptionAlgorithm",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::$BUCKET/*",
"Condition": {
"StringNotEquals": {
"s3:x-amz-server-side-encryption": "aws:kms"
}
}
},
{
"Sid": "DenyMissingKMSKeyHeader",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::$BUCKET/*",
"Condition": {
"Null": {
"s3:x-amz-server-side-encryption-aws-kms-key-id": "true"
}
}
},
{
"Sid": "DenyWrongKMSKey",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::$BUCKET/*",
"Condition": {
"ArnNotEquals": {
"s3:x-amz-server-side-encryption-aws-kms-key-id": "$KMS_KEY_ARN"
}
}
}
]
}
EOF
For a dedicated lab bucket without an existing policy, apply it:
aws s3api put-bucket-policy \
--bucket "$BUCKET" \
--policy file://s3-kms-enforce.json
Do not blindly overwrite an existing production bucket policy.  put-bucket-policy  replaces the policy document. Retrieve the existing policy and merge the new Deny statements into it.
Also note that this strict policy intentionally changes upload behavior.
Even when the bucket has default SSE-KMS encryption, an upload request with no encryption headers will be rejected.
This happens because IAM policy conditions evaluate the request headers, not the eventual encryption applied by S3.
If your goal is only to reject explicit encryption overrides while allowing clients to rely on bucket defaults, design a different policy and test both cases.
For the strict version in this guide, clients must send the required="true" headers.
A default sets the expected behavior. Enforcement rejects requests that violate it.

9. Test Your AWS KMS Configuration

Let's verify the complete encryption workflow.
First, create a file:
printf 'AWS KMS test\n'> kms-test.txt
Upload using the required encryption headers:
aws s3api put-object \
--bucket "$BUCKET" \
--key kms-demo/kms-test.txt \
--body kms-test.txt \
--server-side-encryption aws:kms \
--ssekms-key-id "$KMS_KEY_ARN" \
--region "$AWS_REGION"
Run this using an authorized identity with the required S3 and KMS access.
Now inspect the metadata:
aws s3api head-object \
--bucket "$BUCKET" \
--key kms-demo/kms-test.txt \
--region "$AWS_REGION" \
--query '{
Encryption:ServerSideEncryption,
Key:SSEKMSKeyId,
BucketKey:BucketKeyEnabled
}'
Illustrative result:
{
"Encryption": "aws:kms",
"Key": "arn:aws:kms:us-east-1:123456789012:key/...",
"BucketKey": true
}
Next, download the object:
aws s3api get-object \
--bucket "$BUCKET" \
--key kms-demo/kms-test.txt \
--region "$AWS_REGION" \
downloaded-test.txt
The authorized application should successfully retrieve the plaintext.
Now test a second identity that lacks the necessary permissions.
Test
Authorized role
Role without S3 access
Upload with required headers
Pass
Denied
Download
Pass
Denied
 HeadObject 
Pass
Denied
This is an expected-access matrix, assuming the unauthorized role has no alternative applicable permissions.
Important nuance:  HeadObject  generally does not require KMS  Decrypt  for ordinary object metadata retrieval. An identity with S3 read permission but no KMS decryption permission may be able to read metadata while failing to download the object's content. Requesting checksum information can introduce additional KMS permission requirements.
Test the actual object download to validate your decrypt restrictions.

10. What Happens to Existing S3 Objects?

Here's a production mistake worth avoiding.
Suppose your bucket contained 100,000 objects encrypted with SSE-S3.
You change the default encryption setting to SSE-KMS.
Are all 100,000 existing objects immediately protected by your customer managed KMS key?
No.
Changing the default affects subsequent writes.
Existing objects retain their previous encryption configuration until their encryption is updated.
Depending on the workload, you may use supported S3 encryption-update capabilities or a controlled S3 Batch Operations workflow.
Before migrating:
  • Inventory encryption types.
  • Review bucket versioning and metadata implications.
  • Verify permissions to read and rewrite affected objects.
  • Test a representative sample.
  • Estimate operational and KMS costs.
  • Validate results after migration.
Remember that copy-based migrations may create additional object versions.
Changing a bucket configuration is not the same as migrating its data.

11. AWS KMS Pricing: What Does It Actually Cost?

AWS KMS pricing is often misunderstood because the monthly key charge and per-request charge are separate.
According to the AWS KMS pricing page, checked in October 2026:
Pricing component
Published rate
Customer managed KMS key
$1/month
Standard symmetric KMS requests
$0.03 per 10,000 requests
Eligible free tier
20,000 requests/month
First automatic/on-demand rotation
Additional $1/month
Second rotation
Another $1/month
Further rotations
No additional rotation-based monthly increase
Monthly key charges are prorated. Free-tier eligibility and request prices depend on the operation and applicable pricing conditions.

Example: 10 million KMS requests per month

Assume:
  • One customer managed key.
  • 10 million standard billable-category requests.
  • The 20,000-request free tier is available.
  • No previous key rotations have added monthly storage charges.
  • S3 Bucket Keys achieve an illustrative 99% reduction in KMS request volume.
Without S3 Bucket Keys:
10,000,000 − 20,000 = 9,980,000 chargeable requests.
Request cost:
 9,980,000 / 10,000 × $0.03 = $29.94 
Add $1 for the key.
Total: $30.94/month.
With S3 Bucket Keys, assuming 99% fewer calls:
100,000 KMS requests remain.
100,000 − 20,000 = 80,000 chargeable requests.
 80,000 / 10,000 × $0.03 = $0.24 
Add $1 for the key.
Total: $1.24/month.
Scenario
Monthly KMS estimate
Without Bucket Keys
$30.94
With Bucket Keys, illustrative 99% reduction
$1.24
Illustrative savings
$29.70
These are hypothetical KMS costs, not a prediction of actual S3 usage. They exclude S3 storage, S3 requests, data transfer, CloudTrail charges, and other AWS costs.
AWS says S3 Bucket Keys can reduce applicable KMS request costs by up to 99%, but actual results depend on workload characteristics.
There is also a security consideration.
With Bucket Keys, the AWS KMS encryption context generally uses the bucket ARN rather than an individual object ARN.
You also receive fewer corresponding KMS CloudTrail events.
If policies rely on object-level encryption context, review and adjust them before enabling Bucket Keys.
Lower costs are valuable. Preserving the intended access controls is essential.

12. Monitor KMS Usage with AWS CloudTrail

Encryption without visibility makes troubleshooting and incident investigation harder.
AWS CloudTrail can record AWS KMS API activity.
Watch for operations such as:
  •  GenerateDataKey : data-key generation.
  •  Decrypt : decryption-key operations.
  •  DisableKey : key disabling.
  •  ScheduleKeyDeletion : scheduling key deletion.
  •  PutKeyPolicy : changes to key permissions.

Example CloudTrail event

Here's a simplified, illustrative KMS  GenerateDataKey  event associated with S3:
{
"eventSource": "kms.amazonaws.com",
"eventName": "GenerateDataKey",
"awsRegion": "us-east-1",
"userIdentity": {
"type": "AssumedRole",
"arn": "arn:aws:sts::123456789012:assumed-role/AppS3Role/app-session"
},
"requestParameters": {
"keyId": "arn:aws:kms:us-east-1:123456789012:key/...",
"encryptionContext": {
"aws:s3:arn": "arn:aws:s3:::example-bucket"
}
},
"resources": [
{
"type": "AWS::KMS::Key"
}
]
}
The example is intentionally trimmed and uses illustrative identities. The bucket-level encryption context shown is consistent with S3 Bucket Key usage.
Look at four fields:
 eventSource  identifies AWS KMS.
 eventName  identifies the operation being performed.
 userIdentity  helps identify the principal associated with the request.
 encryptionContext  provides context about the resource involved.
With S3 Bucket Keys, individual object accesses don't necessarily generate corresponding KMS events.
For object-level visibility, configure appropriate S3 data-event logging.
A useful monitoring architecture is:
 S3/KMS → CloudTrail → EventBridge or CloudWatch → Alert 
Use EventBridge rules, CloudWatch alarms, or your monitoring platform to surface sensitive administrative operations.
For example, unexpected key-policy changes or scheduled key deletion should trigger a security review.
A secure system shouldn't only prevent unauthorized access. It should help you notice suspicious changes.

13. AWS KMS Troubleshooting Guide

When SSE-KMS fails, start with the actual error and identify which layer rejected the operation.
Symptom
Likely cause
What to check
 AccessDenied  on upload
Missing  s3:PutObject ,  kms:GenerateDataKey , or required encryption headers
IAM, bucket policy, key policy, request headers
 AccessDenied  on download
Missing  s3:GetObject  or KMS  Decrypt  authorization
S3 authorization, key policy, IAM permissions
 KMS.DisabledException 
Key is disabled or unusable in its current state
 DescribeKey ; restore only when approved
 KMSInvalidStateException 
Operation incompatible with key state, potentially pending deletion
Key state and requested operation
Region mismatch
Bucket and KMS key are in different Regions
Bucket Region and key ARN
 ThrottlingException 
KMS request quota exceeded
Request rate, backoff, retries, quotas
Some key-state errors vary by operation. Don't assume every  KMSInvalidStateException  means pending deletion.

Diagnose the key state

aws kms describe-key \
--key-id "$KMS_KEY_ARN" \
--region "$AWS_REGION" \
--query 'KeyMetadata.KeyState'
Expected for a usable, enabled key:
 Enabled 
If the key is disabled or pending deletion, cryptographic operations may fail.
For a key in the  PendingDeletion  state, authorized administrators can cancel deletion before the waiting period expires.
Never automatically re-enable a disabled key or cancel deletion without understanding why the state changed.
Key disabling and deletion may have been intentional security actions.

14. Multi-Region Keys and S3 Replication

Cross-Region replication introduces another layer of configuration.
For SSE-KMS encrypted objects, S3 replication requires additional settings.
You must explicitly enable replication of KMS-encrypted objects and provide an appropriate destination-Region KMS key.
Your replication role also requires suitable permissions to decrypt from the source and encrypt at the destination.
Production surprise: S3 doesn't automatically take advantage of AWS KMS multi-Region key interoperability.
Amazon S3 treats multi-Region KMS keys as single-Region keys for its encryption operations.
This means you still need to configure replication and destination key permissions correctly.
For cross-account replication, review both accounts' IAM and KMS key policies.
If S3 Bucket Keys are enabled, remember that the encryption context may be bucket-level rather than object-level.

15. Implement AWS KMS with Terraform

For DevOps teams, repeatability matters.
Instead of creating everything through manual CLI commands, you can manage the encryption configuration using Terraform.
Here's a compact example for an existing bucket.
variable "bucket_name" {
type = string
}

resource "aws_kms_key" "s3_key" {
description = "S3 data encryption"
deletion_window_in_days = 30
enable_key_rotation = true
}

resource "aws_kms_alias" "s3_alias" {
name = "alias/s3-app-data"
target_key_id = aws_kms_key.s3_key.key_id
}

resource "aws_s3_bucket_server_side_encryption_configuration" "s3_encryption" {
bucket = var.bucket_name

rule {
apply_server_side_encryption_by_default {
sse_algorithm = "aws:kms"
kms_master_key_id = aws_kms_key.s3_key.arn
}

bucket_key_enabled = true
}
}
The AWS provider and authentication configuration are assumed to be defined elsewhere.
This Terraform configuration creates a customer managed KMS key, enables rotation, creates an alias, and configures S3 default SSE-KMS encryption.
It does not include the application IAM role, a customized key policy, or strict S3 bucket-policy enforcement.
Those should be incorporated into a production Terraform implementation using managed IAM policy and bucket-policy resources.
When Terraform creates a KMS key without a custom key policy, the normal account-level IAM delegation behavior applies.
Don't mix Terraform and manual resource changes casually. Import or reconcile resources that Terraform doesn't already manage to avoid configuration drift.
Infrastructure as code doesn't eliminate security reviews.
It makes security configurations easier to repeat, test, and audit.

16. When NOT to Use SSE-KMS

SSE-KMS is useful, but it's not automatically the best choice for every bucket.

When SSE-S3 already meets your requirements

If you only need standard encryption at rest and don't require custom KMS policies or key-usage visibility, SSE-S3 may be sufficient.

When request volumes create unnecessary complexity

KMS has request quotas.
A high-throughput workload can encounter throttling if its cryptographic request rate exceeds the applicable account-and-Region quota.
At scale, evaluate S3 Bucket Keys, request-rate patterns, monitoring, retry strategies, and quota increases.

When the operational burden outweighs the benefit

Customer managed KMS keys introduce lifecycle responsibilities.
Incorrect key policies can interrupt workloads.
Disabling or deleting a key can make encrypted data unavailable.
If your team has no requirement for the additional controls, adding another security dependency may not improve the overall system.
Good security is the right control for the risk—not the largest collection of controls.

17. Cleanup: Remove Your Tutorial Resources Safely

A good cloud tutorial should also explain how to tear down its resources.
Only follow this section for a dedicated lab environment.
First, delete the test object:
aws s3api delete-object \
--bucket "$BUCKET" \
--key kms-demo/kms-test.txt
If bucket versioning is enabled, this may create a delete marker rather than remove previous object versions.
Verify and remove test versions separately when appropriate.
Next, remove the tutorial's strict encryption policy statements. If this was a dedicated lab bucket with no other policy requirements, you can delete its bucket policy:
aws s3api delete-bucket-policy \
--bucket "$BUCKET"
For an existing shared bucket, remove only the tutorial statements and preserve the original policy.
Restore the bucket's original encryption configuration.
For a dedicated lab bucket, you may remove the custom default encryption configuration:
aws s3api delete-bucket-encryption \
--bucket "$BUCKET"
New uploads will still receive S3's baseline SSE-S3 encryption.
This does not change the encryption of previously written objects.
Remove the alias:
aws kms delete-alias \
--alias-name alias/s3-app-data \
--region "$AWS_REGION"
Finally, schedule KMS key deletion only after confirming that nothing still depends on the key:
aws kms schedule-key-deletion \
--key-id "$KMS_KEY_ARN" \
--pending-window-in-days 30 \
--region "$AWS_REGION"
AWS KMS allows a deletion waiting period from 7 to 30 days.
During that period, the key is pending deletion and is unavailable for cryptographic operations.
If you change your mind before the waiting period ends, an authorized administrator can cancel the scheduled deletion.
Warning: Deleting a KMS key is destructive.
Data that depends on the deleted key may become permanently unrecoverable.
Never schedule deletion of a production key without reviewing dependent resources, object versions, backups, replication targets, and retention requirements.
For tutorial cleanup, a 30-day waiting period provides more opportunity to detect a mistake than the shortest permissible waiting period.

18. AWS KMS Production Security Checklist

Before deploying SSE-KMS to production, verify:
KMS Key Configuration: A customer managed symmetric KMS key is created in the same AWS Region as the S3 bucket.
  • Key Policy: The KMS key policy grants appropriate permissions to authorized administrators and application roles.
  • Least-Privilege IAM: IAM policies grant only the necessary permissions, such as  kms:GenerateDataKey  and  kms:Decrypt .
  • Key Rotation: Automatic KMS key rotation is enabled and configured according to organizational security requirements.
  • S3 Encryption: Default bucket encryption uses  aws:kms  with the correct customer managed KMS key ARN.
  • Bucket Policy Enforcement: S3 bucket policies prevent unauthorized encryption overrides and enforce the required encryption configuration.
  • Access Validation: Authorized users can upload and download encrypted objects, while unauthorized access attempts are denied.
  • Existing Object Encryption: Previously stored S3 objects have been reviewed and migrated to SSE-KMS where required.
  • CloudTrail Monitoring: AWS CloudTrail records relevant KMS operations, including  Decrypt ,  GenerateDataKey ,  DisableKey , and  ScheduleKeyDeletion .
  • S3 Bucket Keys: S3 Bucket Keys are evaluated for cost savings, KMS request reduction, and auditing implications.
  • Cross-Region Replication: Replication configurations include the appropriate destination KMS keys and required IAM permissions.
  • KMS Key Lifecycle: Procedures exist for key disabling, rotation, recovery, and deletion to prevent accidental data loss.
  • Terraform Management: KMS keys, encryption settings, and security policies are managed through Infrastructure as Code where appropriate.
  • Cost and Quota Monitoring: AWS KMS request costs, usage patterns, and throttling limits are monitored.
  • Production Testing: Encryption settings, IAM permissions, key policies, application workflows, and failure scenarios are validated before deployment.




19. Frequently Asked Questions

Is AWS KMS encryption enabled by default for S3?

No. S3 automatically encrypts new uploads with SSE-S3 unless another encryption configuration applies. SSE-KMS requires selecting KMS-based encryption.

What's the difference between SSE-S3 and SSE-KMS?

Both provide server-side encryption. SSE-KMS adds AWS KMS-based key authorization, management, and audit capabilities.

Does key rotation re-encrypt existing S3 objects?

No. Automatic KMS key rotation changes key material for subsequent cryptographic operations but doesn't automatically rewrite existing S3 objects.

Why can an application access S3 but not decrypt objects?

It may have the correct S3 permissions but lack the required KMS authorization. Check key policies, IAM, grants, and explicit denies.

Does enabling S3 Bucket Keys reduce costs?

It can. AWS documents a reduction of up to 99% in applicable KMS request costs. The actual benefit depends on workload behavior.

Can Terraform manage AWS KMS encryption?

Yes. Terraform supports KMS keys, aliases, S3 encryption configurations, IAM policies, and bucket policies.

Final Thoughts: Encryption Is Easy. Key Control Takes Discipline.

You can enable encryption in a few clicks.
But building secure cloud infrastructure requires more than switching it on.
You need to understand:
Who can access the stored data?
Who can use the encryption key?
What happens when permissions change?
What happens when a key is disabled?
Can you prove unauthorized access is denied?
Can you recover when something goes wrong?
AWS KMS gives you the tools to answer these questions.
Your responsibility is to configure and operate those controls correctly.
The real measure of security isn't how many protections you've enabled. It's how well you understand and verify them.
Start with the appropriate encryption model.
Apply least privilege.
Enforce the requirements that matter.
Monitor key usage.
Test failure scenarios.
And never delete a key without understanding what depends on it.
Because secure cloud infrastructure isn't defined by a green checkbox.
It's defined by what still works—and what correctly fails—when that security is tested.
Technical references
Open to Cloud Ops Remote and technical writing projects.









Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article