返回响应后,Lambda可以继续吗? [英] Can Lambda continue after returning response?

查看:67
本文介绍了返回响应后,Lambda可以继续吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

推荐答案

关于从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.

另外使用

对于非异步处理程序,函数将继续执行,直到事件循环为空或函数超时为止.直到所有事件循环任务完成后,响应才会发送给调用者.如果函数超时,则返回错误.您可以通过将 context.callbackWaitsForEmptyEventLoop 设置为false,来配置运行时立即发送响应.

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.

这篇关于返回响应后,Lambda可以继续吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆