[英]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.