[英]AWS Lambda Python S3 Read File Error
尝试从s3中的存储桶读取文件。 存储桶具有连接到python lambda函数的触发器。 然后,当将新文件放入存储桶时,它将运行。 我不断收到错误消息。
此代码:
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中的管理员。
任何帮助将非常感激
此错误是由创建boto3 客户端而不是resource引起的 。
示例(将重现您的错误):
s3 = boto3.client('s3')
s3.meta.client.download_file(bucket, key, localFilename)
您有两种解决方案:
1)更改为使用“ 高级抽象 ” s3资源:
s3 = boto3.resource('s3')
s3.meta.client.download_file(bucket, key, localFilename)
2)直接使用“ 低级 ” s3客户端download_file()
s3 = boto3.client('s3')
s3.download_file(bucket, key, localFilename)
我认为可能是变量s3
对象类型错误引用。 当s3
是ResourceMeta
对象时,可能会使用s3.meta.client
,但是在这里我认为s3
是Client
对象。
所以你可以写
try: s3.download_file(bucket, key, localFilename) except Exception as e: ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.