[英]AWS Lambda in Python to copy new files to another s3 bucket
[英]Readming .tif files in AWS S3 bucket through lambda function which are contained in another directory
bucket = event['Records'][0]['s3']['bucket']['name']
key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')
try:
response = s3.get_object(Bucket=bucket, Key=key)
x = gdal.Open(response).ReadAsArray()
我已使用默認測試事件從 S3 獲取文件以檢查其操作,並且在使用“響應”變量時出現以下錯誤。
{
"errorMessage": "not a string",
"errorType": "RuntimeError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 107, in lambda_handler\n raise e\n",
" File \"/var/task/lambda_function.py\", line 30, in lambda_handler\n x = gdal.Open(response).ReadAsArray()\n",
" File \"/opt/python/osgeo/gdal.py\", line 3308, in Open\n return _gdal.Open(*args)\n"
]
}
當我使用作為字符串的“key”變量時,出現以下錯誤:
{
"errorMessage": "'NoneType' object has no attribute 'ReadAsArray'",
"errorType": "AttributeError",
"stackTrace": [
" File \"/var/task/lambda_function.py\", line 107, in lambda_handler\n raise e\n",
" File \"/var/task/lambda_function.py\", line 30, in lambda_handler\n x = gdal.Open(key).ReadAsArray()\n"
]
}
ERROR 4: cog_aridity.tif: No such file or directory
雖然,當我用 .json 替換測試事件中的 .tif 文件時,文件可以正常讀取。
.tif 不適用於 lambda,我猜只有 png、pdf 等。您需要使用 lambdape 將其轉換為 jpeg,然后從存儲桶中讀取 3。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.