返回响应后,Lambda可以继续吗? [英] Can Lambda continue after returning response?
问题描述
Lambda是否有可能在返回状态码为 202
之类的响应后继续处理,然后Lambda必须在结束Lambda之前调用请求?
Is it possible for Lambda to continue processing after returning a response like the status code is 202
then Lambda will have to call a request before ending the Lambda?
推荐答案
Regarding background processes or callbacks initiated before the function returns a response, from the Lambda docs:
如果AWS Lambda选择重用执行上下文,则由Lambda函数启动的,未完成的后台进程或回调将在函数结束时恢复.您应确保在代码退出之前完成代码中的所有后台进程或回调.
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.
编写Lambda函数代码时,请勿假定AWS Lambda自动将执行上下文重新用于后续函数调用.其他因素可能表明需要AWS Lambda创建新的执行上下文,这可能导致意外结果,例如数据库连接失败.
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.