简体   繁体   中英

How to use smart_open to write a stream to a KMS-encrypted S3 bucket?

I'm trying to write a stream to a KMS-encrypted S3 bucket using smart_open, but to no avail. Looking into the code of smart_open, there seems to be a test case for this, but I can't run it:

@_test_case
def test_s3_encrypted_file(benchmark, uri):
    text = 'с гранатою в кармане, с чекою в руке'
    s3_upload = {'ServerSideEncryption': 'AES256'}
    actual = benchmark(write_read, uri, text, 'w', 'r', 'utf-8', s3_upload=s3_upload)
    assert actual == text

And I assumed this would work, but it just says s3_upload is not an option:

file = smart_open.open(url, 'w', transport_params={'session': session, s3_upload={'ServerSideEncryption': 'aws:kms', 'SSEKMSKeyId': key}})
file.write(content)
file.close()

Any idea of what I'm doing wrong?

It looks like this parameter has been renamed recently , so instead of s3_upload it is multipart_upload_kwargs .

I just got this working, per your example:

file = smart_open.open(url, 'w', transport_params={'session': session, 'multipart_upload_kwargs': {'ServerSideEncryption': 'aws:kms', 'SSEKMSKeyId': key}})
file.write(content)
file.close()

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM