Business Logic outside the Handler - Serverless Architectures with AWS Lambda

Business Logic outside the Handler

Your Lambda function starts execution at the handler function you define within your code package. Within your handler function you should receive the parameters provided by Lambda, pass those parameters to another function to parse into new variables/objects that are contextualized to your application, and then reach out to your business logic that sits outside the handler function and file. This enables you to create a code package that is as decoupled from the Lambda runtime environment as possible. This will greatly benefit your ability to test your code within the context of objects and functions you’ve created and reuse the business logic you’ve written in other environments outside of Lambda.

The following example (written in Java) shows poor practices where the core business logic of an application is tightly coupled to Lambda. In this example, the business logic is created within the handler method and depends directly on Lambda event source objects.