2
我想上传一个文件到S3使用boto3 file_upload方法。这是非常直接的,直到需要服务器端加密。在过去,我使用put_object来实现这一点。如何添加加密到boto3.s3.transfer.TransferConfig s3文件上传
像这样:
import boto3
s3 = boto3.resource('s3')
s3.Bucket(bucket).put_object(Key=object_name,
Body=data,
ServerSideEncryption='aws:kms',
SSEKMSKeyId='alias/aws/s3')
我现在想直接上传文件使用file_upload方法S3。我无法找到如何将服务器端加密添加到file_upload方法。 file_upload方法可以采取TransferConfig,但我没有看到任何设置加密的参数,但我确实在S3Transfer中看到它们。
我期待这样的事情:
import boto3
s3 = boto3.resource('s3')
tc = boto3.s3.transfer.TransferConfig(ServerSideEncryption='aws:kms',
SEKMSKeyId='alias/aws/s3')
s3.upload_file(file_name,
bucket,
object_name,
Config=tc)
boto3文档
如果我读这正确,第四参数S3.Client.upload_file ()似乎是extraArgs。你能够提供ExtraArgs = {ServerSideEncryption:'aws:kms',SSEKMSKeyId:'alias/aws/s3'}。请注意SSEKMSKeyId(不是SEKMSKeyId)的拼写。 – jarmod