I am loving using lambda functions in AWS. It ideally reduced my time in maintaining the servers anymore. My question is when using lambda there is context object and the ca
Here callback
represented as improvement for context.succeed
.
In addition, the event loop allows Node.js to perform non-blocking I/O operations. if callback
waits longer then you expect, it means there are other not-completed tasks in the event loop you are not aware of and this is a problem - you should know what tasks are waiting in the queue. You can use the following functions to understand why callback
is waiting:
process._getActiveHandles() //gets you handles that are still alive
process._getActiveRequests() //gets you info about active libuv requests.
Freezing the lambda before completing those tasks may lead to unexpected behavior. The next lambda execution can be done on the same container. It means event loop tasks of the previous lambda execution are completed in the current lambda execution.
Also, assuming you have more than one test for exports.handler
, with callback
every test is independent. With context.succeed
, you second test can pass (instead of failing) because of the first test, leaving tasks in the event loop.
context.succeed
is the older way of doing things, and is supported under the 0.10.42 runtime (where the callback
parameter specifically isn't). If you're running on the newer runtimes (4.3 and 6.10), it's included for backwards compatibility, but the "proper" way is now to use the callback
functionality.