Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Lambda continue after returning response?

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?

like image 616
Steven Avatar asked Dec 11 '22 02:12

Steven


2 Answers

Regarding background processes or callbacks initiated before the function returns a response, from the 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.

Additionally for Node.js Lambda functions using non-async handlers:

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.

like image 68
Paradigm Avatar answered Feb 17 '23 15:02

Paradigm


Using only AWS Lambda, it is not possible.

You may want to look into AWS Step Functions in order to solve your problem.

like image 41
dooms Avatar answered Feb 17 '23 13:02

dooms