Lambda 是否有可能在返回状态代码为 202
的响应后继续处理?那么Lambda 将不得不在结束Lambda 之前调用一个请求?
最佳答案
关于在函数返回响应之前启动的后台进程或回调,来自 Lambda docs :
Background processes or callbacks initiated by your Lambda function that did not complete when the function ended resume if AWS Lambda chooses to reuse the execution context. You should make sure any background processes or callbacks in your code are complete before the code exits.
When you write your Lambda function code, do not assume that AWS Lambda automatically reuses the execution context for subsequent function invocations. Other factors may dictate a need for AWS Lambda to create a new execution context, which can lead to unexpected results, such as database connection failures.
另外对于使用 non-async handlers 的 Node.js Lambda 函数:
For non-async handlers, function execution continues until the event loop is empty or the function times out. The response isn't sent to the invoker until all event loop tasks are finished. If the function times out, an error is returned instead. You can configure the runtime to send the response immediately by setting
context.callbackWaitsForEmptyEventLoop
to false.
关于asynchronous - 返回响应后,Lambda 可以继续吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57491893/