0

After looking at the AWS Lambda documentation and some stackoverflow questions (especially this one: Context vs Callback in AWS Lambda), I'm still a little confused what the purpose of callback or context.success() is. Also, what was the original reason behind having context.success() back when callback couldn't be used?

I'm asking because I was given a Lambda function that uses both calls, and I don't know why one was chosen over the other at a given point.

Thanks!

user10124766
  • 120
  • 6

1 Answers1

1

From this article:

Context.succeed [is] more than just bookkeeping – [it] cause[s] the request to return after the current task completes and freeze[s] the process immediately, even if other tasks remain in the Node.js event loop... [On the other hand,] the callback waits for all the tasks in the Node.js event loop to complete, just as it would if you ran the function locally. If you chose to not use the callback parameter in your code, then AWS Lambda implicitly calls it with a return value of null. You can still use the Context methods to terminate the function, but the callback approach of waiting for all tasks to complete is more idiomatic to how Node.js behaves in general.*

Sam H.
  • 4,091
  • 3
  • 26
  • 34