Serverless Development
Lambda Function
A small executable that can be imagined as a main method in Java. It has 3 components, which are :
- Handler
- Controller
- Service
A Handler should have the function configuration, lambda specific code and no business logic. A Controller is for event processing and has the Core Business Logic. A Service contains external integrations and service abstractions.
It can also be integrated with Libraries and Frameworks.
A lambda undergoes a cold start followed by a warm start. The order is :
- Download code and start Execution Context(Cold)
- Bootstrap the runtime(Cold)
- Start your code(Hot)
The bootstrap time can be limited by :
- Minimizing dependencies
- Considering startup costs
- Link compiled librs statically
AWS SAM(Serverless Application Manager)
ZIPing and Packaging is automated using SAM CLI. This is made easy by using the following :
sam package
sam deploy
So 2 recommendations :
- Use Serverless Application Framework
- Use a SAM template to deploy serverless apps rather than creating one in AWS CloudFormation
Organizing Lambdas
Service based packaging to be done. Each function should be organized as per the service and each service is given a deployment template and one code repository.
Structuring Development Environment
- Create separate AWS accounts for each developer
- Separate production and non-prod envs into different accounts
Testing and Debug strategy
Recommended Test Strategy :
Debugging code :
- Debugging is not allowed for Lambda Service
- SAM CLI allows launching a local Docker image with debug strategies