AWS S3: Enable encryption through API/Script

拈花ヽ惹草 提交于 2019-12-25 06:39:15

问题


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 uploading again?

I see Boto module in Python allows to clone the key with additional parameters e.g encryption, but this will create a new key. As these keys are stored in a separate database, we want to retain existing keys but just enable encryption.


回答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.



来源:https://stackoverflow.com/questions/32869556/aws-s3-enable-encryption-through-api-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!