【发布时间】:2018-10-10 06:26:24
【问题描述】:
我正在尝试从一个 s3 存储桶中读取一个 excel 文件,并使用 aws lambda 中的 boto3 将其写入另一个存储桶。我已经为我的角色提供了完整的 s3 访问权限并编写了以下代码
import boto3
import botocore
import io
def lambda_handler(event, context):
s3 = boto3.resource('s3')
s3.Bucket('<first_bucket>').download_file('<file_name>.xlsx', '/tmp/<file_name>.xlsx')
object = s3.Object('<first_bucket>','<file_name>.xlsx')
with open('/tmp/<file_name>', 'wb') as data:
object.download_fileobj(data)
target_object = s3.Object('<second_bucket>','<file_name>.xlsx')
target_object.put(data)
return 'Successfully written to new bucket'
我在 Lambda 中执行了此代码,当我检查我的第二个存储桶时,我可以看到该文件存在,但它的大小为 0。我不确定为什么以及如何更正此问题。有什么指点吗?
【问题讨论】:
标签: python-3.x amazon-web-services amazon-s3 aws-lambda boto3