2016-03-08 119 views
3

当我有写入蟒,做一些操作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 

回答

5

真正的问题是,拉姆达是使用VPC,但VPC没有端点访问S3。 所以确保你有。

(并允许拉姆达足够的权限调用S3)

现在,它在不到一秒钟的功能。

0

你的输出是非常明显的:

任务121.00秒

好像2分钟,只是不够成功上传文件后超时。 尝试用较小的文件重现此问题。您也可以尝试为超时设置设置最大值(5分钟)。

+0

文件很小200K ..我觉得很难相信,在数据中心的功能有麻烦内将其传送..我会增加超时并在5分钟后报到 – Marcom

+0

YEP仍然超时。我认为还有一些其他的潜在问题。 – Marcom

+0

我敢打赌,如果您尝试上传少量文件,您的功能将成功完成。有没有可能试试这个?我还可以看到'在你的代码'打印( '上传的/ tmp /' + pictureName + '' +桶+ '' + upload_path)。你看到任何显示成功上传的日志记录吗? –