【发布时间】:2017-11-19 11:03:50
【问题描述】:
尝试从 s3 的存储桶中读取文件。存储桶有一个连接到 python lambda 函数的触发器。然后在将新文件放入存储桶时运行。我不断收到错误消息。
这是代码:
将文件从 S3 下载到本地文件系统
try:
s3.meta.client.download_file(bucket, key, localFilename)
except Exception as e:
print(e)
print('Error getting object {} from bucket {}. Make sure they exist and your bucket is in the same region as this function.'.format(key, bucket))
raise e
我收到此错误
'ClientMeta' 对象没有属性'client'
我认为它可能是 IAM,但 Lambda 函数具有 AWSLambdaFullAccess 角色,这几乎是 S3 中的管理员。
任何帮助将不胜感激
【问题讨论】:
-
在我看来,
s3.meta好像没有client对象,所以上面的调用甚至在到达 AWS 之前就失败了。我猜这个例外是AttributeError?请编辑您的问题,以包括变量s3从何处获取其值。还请包括完整的回溯。 -
为什么不用boto3 s3低级客户端下载文件。
import boto3 # Get the service client s3 = boto3.client('s3') # Download object at bucket-name with key-name to tmp.txt s3.download_file("bucket-name", "key-name", "tmp.txt").
标签: python amazon-web-services amazon-s3 lambda amazon-iam