
Handler
The handler is the entry point to the Lambda function. It encapsulates the outermost boundary of the code that is to be executed. Think of it as the main function of your Lambda. It is the first frame that gets pushed into the execution stack, and the last one that gets popped during unwinding.
The handler gets passed the event data that triggers the execution and the context as parameters. The handler can call other functions as it sees fit.
A typical definition of a handler would look as follows, in a hypothetical programming language:
ReturnType FunctionName (InputType input ,Context ctx);
Lets have a look at the different components of the function signature -
- The ReturnType is the data structure that encapsulates the execution output.
- The InputType is the data structure that encapsulates the input to the Lambda function. These can be preconfigured or custom event sources.
- The Context is the object that encapsulates the execution environment that the function is executing in.
For Lambda functions written in JavaScript, which supports callbacks, a third parameter is passed to the function, which is exactly what it says on the tin: code that executes after the first function has finished execution. In this scenario, the Lambda signature is as follows:
ReturnType FunctionName(InputType input, Context ctx, Callback callback);