當我有寫入蟒,做一些操作MongoDB中然後它應該是從功能的tmp文件夾的圖片上載到S3 lambda函數。該功能在上傳步驟中保持超時。lambda函數超時上傳到S3
我提出的超時2分鐘和函數具有S3和VPC的權限。該功能簡單地超時。任何人有任何想法是什麼問題?
樣品輸入
#picturename should be created by the app. a name unique for the dish
{
"UserId": "56dc63fc1769d032d4d78e2e",
"DishId": "56dcc2781769d032d4d78e2f",
"PictureName" : "katsu-001.png",
"Data": "base64 image just the bits ignore data:image/jpeg;base64, if you have it"
}
功能
def addPicture(event,context):
from __future__ import print_function
import pymongo
from pymongo import MongoClient
import bson.code
from bson.objectid import ObjectId
import datetime
import json
import boto3
import sys
import uuid
from base64 import decodestring
print ('Writing file to disk')
with open('/tmp/' + pictureName,"wb") as f:
f.write(decodestring(event["Data"]))
print ('File written to /tmp/' + pictureName)
s3_client = boto3.client('s3')
print ('Starting S3 upload')
bucket = "foundue-dev-filestore"
upload_path = 'pictures/dish/' + dishId.__str__() + '/' + pictureName
print ('Uploading /tmp/' + pictureName + ' ' + bucket + ' ' + upload_path)
s3_client.upload_file('/tmp/' + pictureName,bucket, upload_path)
print ('Upload Complete')
#pics[pictureName] = upload_path
#dish["Pictures"] = pics
#dish["UpdatedOn"] = datetime.datetime.utcnow()
#db.dishes.replace_one({"_id": dishId}, dish)
return
政策附加到拉姆達
oneClick_lambda_basic_vpc_execution_1457284829450
oneClick_lambda_s3_exec_role_1457392283800
輸出
Loading function
START RequestId: ed91c290-e582-11e5-95d6-ed4fc6a3321b Version: $LATEST
Writing file to disk
File written to /tmp/katsu-002png
Starting S3 upload
Uploading /tmp/katsu-002png foundue-dev-filestore pictures/dish/56dcc2781769d032d4d78e2f/katsu-002png
END RequestId: ed91c290-e582-11e5-95d6-ed4fc6a3321b
REPORT RequestId: ed91c290-e582-11e5-95d6-ed4fc6a3321b Duration: 121003.49 ms Billed Duration: 121000 ms Memory Size: 128 MB Max Memory Used: 22 MB
2016-03-08T23:12:21.437Z ed91c290-e582-11e5-95d6-ed4fc6a3321b Task timed out after 121.00 seconds
文件很小200K ..我覺得很難相信,在數據中心的功能有麻煩內將其傳送..我會增加超時並在5分鐘後報到 – Marcom
YEP仍然超時。我認爲還有一些其他的潛在問題。 – Marcom
我敢打賭,如果您嘗試上傳少量文件,您的功能將成功完成。有沒有可能試試這個?我還可以看到'在你的代碼'打印( '上傳的/ tmp /' + pictureName + '' +桶+ '' + upload_path)。你看到任何顯示成功上傳的日誌記錄嗎? –