asynchronous - 返回响应后,Lambda 可以继续吗?

标签 asynchronous aws-lambda serverless

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/

相关文章:

无服务器错误 - 没有文件匹配包含/排除模式

amazon-web-services - AWS Step Function 同步任务 token

javascript - 来自 lambda 函数的 API 网关的 502 内部服务器错误响应

aws-cloudformation - 无服务器安装后 CircleCI 找不到无服务器框架

javascript - 单个值的 Observable 与 Promise

c++ - 如何在C++上启动异步线程

amazon-web-services - AWS lambda 无法创建计划事件源

mysql - 如何将 python mysql.connector 包含到 AWS Chalice 部署中?

jQuery - 当您需要等待所有数据时循环调用 getJSON 的最佳方法?

node.js - MQTTjs 库的无序输出