【发布时间】:2016-04-13 17:04:52
【问题描述】:
使用 Boto3: 我正在使用 put_object() 函数在 s3 中上传对象。我正在使用 put_object() 和客户加密密钥参数进行服务器端加密。
使用博托: 我正在使用 upload_chunk 函数在 s3 中上传对象。在这里,我使用 AWS 托管密钥进行服务器端加密,而不是客户提供的,因为 API 不支持它
因此,使用 Boto3 方法,我的程序比 Boto 方法占用更多内存。 请告诉我 put_object 函数如何在 boto3 中用于服务器端加密。
它是否使用机器的内存进行它调用的加密?
我是否应该明确清理作为 Body 参数传递给 put_object 函数的数据缓冲区?
代码:
def put_s3_object(self, target_key_name, data, sse_cust_key, sse_cust_key_md5):
''' description: Upload file as s3 object using SSE with customer key
It will store s3 object in encrypted format
input:
target_key_name (#string) data(in memory string/bytes)
sse_cust_key (#string)
sse_cust_key_md5 (#string)
output: response
'''
if not target_key_name:
raise
try:
response = self.s3_client.put_object(Bucket = self.source_bucket, Body = data, Key = target_key_name, SSECustomerAlgorithm = awsParams.CLOUD_DR_AWS_SSE_ALGO, SSECustomerKey = sse_cust_key, SSECustomerKeyMD5 = sse_cust_key_md5)
del data
except botocore.exceptions.ClientError, fault:
raise
except Exception, fault:
raise
【问题讨论】:
-
嗯,有源代码:-D github.com/boto/boto3
-
@mootmoot:感谢您的回复。我直接使用了 put_object() 而不是 upload_file()。这是因为在 boto3 upload_file() 中需要文件名作为参数。它不支持数据缓冲区作为参数。我想将数据缓冲区作为参数发送到 s3 中上传。是否必须使用 upload_file () ?不建议在boto3中直接使用put_object()吗?
-
恕我直言,aws 开发人员推出 boto3 而不是为 boto 修补功能是有原因的。我认为使用 put_object 没有任何问题。 Body 接受流对象,例如文件句柄、StringIO、ByteIO 等。如果要上传物理文件,只需 open() 文件并传递文件处理程序。如果您想在将内容放入 put_object() 之前操作处理程序内容,您只需要小心
-
@mootmoot 感谢您的回复。将 put_object() 与服务器端加密参数一起使用后,我的内存使用量会持续 5-6 小时。如果我在 put_object () 函数调用中缺少任何参数,请通知我
-
@mootmoot 我是否需要调用任何 cleanup() 来释放我消耗的内存? put_object() 调用中是否有任何参数可以清理消耗的内存?
标签: python-2.7 boto boto3