The Handler - Serverless Architectures with AWS Lambda

The Handler

When a Lambda function is invoked, code execution begins at what is called the handler. The handler is a specific code method (Java, C#) or function (Node.js, Python) that you’ve created and included in your package. You specify the handler when creating a Lambda function. Each language supported by Lambda has its own requirements for how a function handler can be defined and referenced within the package.

The following links will help you get started with each of the supported languages.

Language Example Handler Definition
Java
MyOutput output handlerName(MyEvent event, Context context) { ... }
Node.js
exports.handlerName = function(event, context, callback) { ... // callback parameter is optional }
Python
def handler_name(event, context): ... return some_value
C#
myOutput HandlerName(MyEvent event, ILambdaContext context) { ... }

Once the handler is successfully invoked inside your Lambda function, the runtime environment belongs to the code you’ve written. Your Lambda function is free to execute any logic you see fit, driven by the code you’ve written that starts in the handler. This means your handler can call other methods and functions within the files and classes you’ve uploaded. Your code can import third-party libraries that you’ve uploaded, and install and execute native binaries that you’ve uploaded (as long as they can run on Amazon Linux). It can also interact with other AWS services or make API requests to web services that it depends on, etc.