How to wait for async actions inside AWS Lambda?

前端 未结 7 751
深忆病人
深忆病人 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:17

    Think of Lambda simply as a program that you can run in a certain amount of time. The fact that you make asynchronous calls is nice since the (virtual) processor can possibly interleave those calls. However, if any part of your Lambda program takes longer to complete than the time allotted, well, execution will fail. That's the compromise you make and is how Amazon makes money; by selling you more time or memory.

    To fix that on your end you can increase the memory your Lambda function is allotted. This not only increases your RAM but also the speed of your virtual processor. Another thing you can do is increase the timeout. AWS Lambda now allows you up to 512 MB of RAM and up to 5 minutes of processing time. As of this post those numbers may have changed so check here for the latest limits. To change this setting, go to your function, then configuration and finally advanced.

提交回复
热议问题