【发布时间】:2019-06-26 14:00:24
【问题描述】:
在 AWS lambda 中,我使用 boto3 将字符串放入 S3 文件:
import boto3
s3 = boto3.client('s3')
data = s3.get_object(Bucket=XXX, Key=YYY)
data.put('Body', 'hello')
有人告诉我:
[ERROR] AttributeError: 'dict' object has no attribute 'put'
data.put('hello') 也是如此,这是How to write a file or data to an S3 object using boto3 的热门答案推荐的方法,data.put_object:'dict' object has no attribute 'put_object'。
我做错了什么?
相反,阅读效果很好(data.get('Body').read().decode('utf-8'))。
【问题讨论】:
-
我发现使用S3最简单的方法是在本地创建一个文件,然后通过
put_object()上传。这样,您就可以将“文件创建”与“文件上传”分开,从而使调试变得更容易。
标签: python-3.x dictionary amazon-s3 aws-lambda boto3