Reputation: 39279
I would like to change the server_side_encryption
settings for an S3 object (preferably using boto3
).
As far as I understand I cannot actually change S3 object setting like this, and will instead need to "copy" the object with the new settings. Firstly, is this true? If so, is it possible to copy an S3 object to the same key (in one operation), thus overwriting the original file with a new file with new settings?
Upvotes: 0
Views: 905
Reputation: 270224
Yes, you can copy a file to itself to change the Server-Side encryption settings.
Here is a sample using the AWS Command-Line Interface (CLI):
aws s3 cp s3://my-bucket/foo.txt s3://my-bucket/foo.txt --sse AES256
Upvotes: 1
Reputation: 81454
AWS S3 objects cannot be modified once created. You cannot write to them in-place, append,etc. AWS does support changing an S3 object by copying it in-place while making the changes. Encryption falls into that category.
Here is a python example from John Rotenstein on how to encrypt files that are already in S3. Add a vote to John's answer it it helps you.
John Rotenstein's example:
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)
Upvotes: 1