I'm using the following snippet to upload my files to the AWS S3 buckets:
import boto3
def upload_to_s3(bucket_name, local_name, name):
bucket = boto3.resource('s3').Bucket(my_bucket_name)
bucket.upload_file(local_name, name)
Is there any way to modify this code to enable SSE?
There are 2 ways.
use this: https://www.justdocloud.com/2018/09/21/upload-download-s3-using-aws-kms-python/
s3_client.upload_file(filename, bucketname, objectkey, ExtraArgs={"ServerSideEncryption": "aws:kms", "SSEKMSKeyId": })
Enable Default bucket encryption with KMS on bucket and make sure the user/role you're using to upload has KMS permission, this way you don't need to define any kms key here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.