Skip to content

Latest commit

 

History

History
36 lines (21 loc) · 1.55 KB

File metadata and controls

36 lines (21 loc) · 1.55 KB

S3 Encryption

An AWS CLI tutorial that demonstrates S3 operations.

Running

bash s3-encryption.sh

To auto-run with cleanup:

echo 'y' | bash s3-encryption.sh

What it does

  1. Creating bucket"; B="enc-tut-$(cat /dev/urandom | tr -dc 'a-z0-9' | fold -w 8 | head -n 1)-$(aws sts get-caller-identity --query Account --output text)"; aws s3api create-bucket --bucket "$B" > /dev/null; echo "Step 2: Enabling SSE-S3"; aws s3api put-bucket-encryption --bucket "$B" --server-side-encryption-configuration '{"Rules":[{"ApplyServerSideEncryptionByDefault":{"SSEAlgorithm":"AES256"}}]}'; echo "Step 3: Checking encryption"; aws s3api get-bucket-encryption --bucket "$B" --query "ServerSideEncryptionConfiguration.Rules[0].ApplyServerSideEncryptionByDefault" --output table; echo "Step 4: Uploading encrypted object"; echo test > /tmp/enc.txt; aws s3 cp /tmp/enc.txt "s3://$B/test.txt" --quiet; aws s3api head-object --bucket "$B" --key test.txt --query "{Encryption:ServerSideEncryption}" --output table; echo "Do you want to clean up? (y/n): "; read -r C; [[ "$C" =~ ^[Yy]$ ]] && { aws s3 rm "s3://$B" --recursive --quiet; aws s3 rb "s3://$B

Resources created

  • Bucket
  • Bucket Encryption

The script prompts you to clean up resources when it finishes.

Cost

Free tier eligible for most operations. Clean up resources after use to avoid charges.

Related docs