How to wait for async actions inside AWS Lambda?

前端 未结 7 779
深忆病人
深忆病人 2020-12-07 17:42

I am trying to process uploaded file in S3. Since getObject is asyncronous main function ends before processing is done, and AWS kills lambda in 3-4 seconds

7条回答
  •  天涯浪人
    2020-12-07 18:16

    I think your lambda function should end with a context.done() call. For instance, try adding it this way:

    s3.getObject(params, function(err, data) {
        if (err) {
             ...
            context.done("Error: " + err.stack);
        } else {
            processFile(data.Body.toString(), 0);
            console.log("ok");
            context.done(null, "success");
        }
    });
    

提交回复
热议问题