Skip to content Skip to sidebar Skip to footer

AWS S3: Enable Encryption Through API/Script

We have images stored in the AWS S3 for our production services. Is there any API which will allow to enable encryption on these existing resources without downloading and uploadin

Solution 1:

Here's some code that will convert all files in a bucket to use server-side encryption:

import boto

conn = boto.connect_s3('REGION')
bucket = conn.get_bucket('BUCKET')

for k in bucket.list():
  bucket.copy_key(new_key_name=k.key, src_bucket_name=bucket.name, src_key_name=k.key, encrypt_key=True)

It copies to the same key name, but you might want to tweak it to preserve storage class, ACLs, etc.


Post a Comment for "AWS S3: Enable Encryption Through API/Script"