Good question 💪 — encrypting your S3 bucket is a best practice for securing data at rest. Let’s go step-by-step 👇
🧠 Concept
S3 supports Server-Side Encryption (SSE) — this means AWS encrypts your objects after they’re uploaded, and decrypts them when you download them. There are 3 main types:
| Encryption Type | Key Managed By | Description |
|---|---|---|
| SSE-S3 | AWS | AWS manages the encryption keys for you (AES-256). |
| SSE-KMS | AWS KMS | You manage the encryption keys through AWS KMS (more control). |
| SSE-C | Customer | You manage your own keys (less common). |
✅ Easiest: SSE-S3 (Managed by AWS)
To enable encryption on a bucket so all objects are automatically encrypted with SSE-S3:
Option 1: Using AWS Console
- Go to S3 → Your Bucket → Properties.
- Scroll down to Default encryption.
- Click Edit.
- Choose Enable and select Amazon S3-managed keys (SSE-S3).
- Save changes.
✅ More Control: SSE-KMS (Managed by KMS)
Use this if you want to manage the keys or control access with IAM policies.
Option 1: Using AWS Console
- Go to S3 → Your Bucket → Properties.
- Scroll to Default encryption → Edit.
- Select AWS Key Management Service keys (SSE-KMS).
- Choose AWS-managed key (
aws/s3) or a custom KMS key you created. - Save changes.
Option 2: Using AWS CLI
aws s3api put-bucket-encryption \
--bucket my-secure-bucket \
--server-side-encryption-configuration '{
"Rules": [{
"ApplyServerSideEncryptionByDefault": {
"SSEAlgorithm": "aws:kms",
"KMSMasterKeyID": "arn:aws:kms:ap-south-1:123456789012:key/abcd-1234-efgh-5678"
}
}]
}'🔒 Optional: Block Unencrypted Uploads
To make sure users can’t upload unencrypted files, add a bucket policy like this:
{
"Version": "2012-10-17",
"Id": "S3BucketPolicy",
"Statement": [
{
"Sid": "DenyUnEncryptedObjectUploads",
"Effect": "Deny",
"Principal": "*",
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my-secure-bucket/*",
"Condition": {
"StringNotEquals": {
"s3:x-amz-server-side-encryption": "aws:kms"
}
}
}
]
}🔸 Replace
"my-secure-bucket"with your actual bucket name. 🔸 This ensures all uploads must use encryption (either SSE-S3 or SSE-KMS).
⚙️ Verification
You can verify encryption using:
aws s3api get-bucket-encryption --bucket my-secure-bucket