context.success() 和 callback() 背后的目的

Purpose behind context.success() and callback()

在查看了 AWS Lambda 文档和一些 Whosebug 问题(尤其是这个问题:)之后,我仍然有点困惑回调或 context.success() 的目的是什么。另外,在无法使用回调时返回 context.success() 的最初原因是什么?

我问是因为我得到了一个使用这两个调用的 Lambda 函数,我不知道为什么在给定的时间点选择了一个而不是另一个。

谢谢!

来自this article

Context.succeed [is] more than just bookkeeping – [it] cause[s] the request to return after the current task completes and freeze[s] the process immediately, even if other tasks remain in the Node.js event loop... [On the other hand,] the callback waits for all the tasks in the Node.js event loop to complete, just as it would if you ran the function locally. If you chose to not use the callback parameter in your code, then AWS Lambda implicitly calls it with a return value of null. You can still use the Context methods to terminate the function, but the callback approach of waiting for all tasks to complete is more idiomatic to how Node.js behaves in general.*