Last active
April 25, 2022 11:48
-
-
Save agassner/14f5f5c90ec0684524562da5ea895432 to your computer and use it in GitHub Desktop.
S3 upload and copy with encryption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import boto3 | |
from boto3.s3.transfer import S3Transfer | |
filename = 'file.txt' | |
bucket_name = 'ravenskill' | |
s3 = boto3.resource('s3') | |
client = s3.meta.client | |
transfer = S3Transfer(client) | |
transfer.upload_file(filename, | |
bucket_name, | |
filename, | |
extra_args={'ServerSideEncryption': 'AES256'}) | |
copy_source = { | |
'Bucket': bucket_name, | |
'Key': filename | |
} | |
bucket = s3.Bucket(bucket_name) | |
obj = bucket.Object(filename) | |
obj.copy(copy_source, | |
ExtraArgs={'ServerSideEncryption': 'AES256'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You don't need to pass AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY values.
Have a look at https://boto3.amazonaws.com/v1/documentation/api/latest/guide/quickstart.html#configuration