A Lambda starter kit for Node.js TypeScript serverless functions.
This project provides a solid foundation for implementing Serverless Microservice Patterns with AWS Lambda functions using Node.js and TypeScript. The project uses the AWS CDK for infrastructure as code, Jest for testing, and modern development tooling.
There are many Serverless Microservice Patterns which may be implemented with AWS Lambda functions. This project illustrates the "Simple Web Service" pattern, which is one of the most frequently used.
Before you begin, ensure you have the following installed:
- Node Version Manager (NVM) - Manages Node.js versions
- Node.js - JavaScript runtime (install via NVM)
- npm - Package manager (comes with Node.js)
- AWS CLI - For AWS credentials and configuration (recommended)
This project uses the Node.js version specified in .nvmrc. See the official nvm guide for additional information.
# Install NVM (if not already installed)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# Install and use the correct Node.js version
nvm install
nvm use
# Verify installation
node --version # Should output same version as in .nvmrc# Install project dependencies
npm installThis is a high-level overview of the project structure. This structure separates the infrastructure as code from the Lambda application code. Within the Lambda microservice component, directories provide structure to implement DRY (Don't Repeat Yourself) code which follows the SRP (Single Responsibility Principle).
/docs # Project documentation
/infrastructure # AWS CDK infrastructure code
/stacks # CDK stack definitions
/utils # CDK utilities and helpers
app.ts # CDK app entry point
cdk.json # CDK configuration
jest.config.ts # Infrastructure Jest configuration
package.json # Infrastructure dependencies and scripts
tsconfig.json # Infrastructure TypeScript configuration
.env.example # Infrastructure example .env
/src # Application source code
/handlers # Lambda function handlers
/models # Data models and types
/services # Business logic services
/utils # Utility functions and helpers
eslint.config.mjs # ESLint configuration
jest.config.ts # Jest testing configuration
package.json # Project dependencies and scripts
tsconfig.json # TypeScript configuration
.nvmrc # Node.js version specification
.prettierrc # Prettier formatting configuration
.editorconfig # Editor configuration
# Build TypeScript to JavaScript
npm run build
# Clean generated files and directories
npm run clean# Format code with Prettier
npm run format
# Check code formatting without making changes
npm run format:check
# Lint code with ESLint
npm run lint
# Lint and auto-fix issues
npm run lint:fix# Run tests without coverage
npm test
# Run tests with coverage report
npm run test:coverage
# Run tests in watch mode (reruns on file changes)
npm run test:watch- Language: TypeScript
- Platform: AWS Lambda
- Runtime: Node.js 24+ (see .nvmrc)
- Package Manager: npm
- AWS SDK: v3
- Testing: Jest
- Linting/Formatting: ESLint + Prettier
- Validation: Zod
- Logging: Pino + Pino Lambda
- Infrastructure: AWS CDK
- DevOps: GitHub Actions
- @aws-sdk/client-dynamodb - AWS SDK v3 DynamoDB client
- @aws-sdk/client-sns - AWS SDK v3 SNS client
- @aws-sdk/lib-dynamodb - DynamoDB document client utilities
- zod - TypeScript-first schema validation
- pino - Low overhead, fast logger for JavaScript
- @types/aws-lambda - TypeScript definitions for AWS Lambda
- jest - Testing framework
- eslint - Linting utility
- prettier - Code formatter
The project supports multiple environments:
- dev - Development environment
- qat - Quality Assurance/Testing environment
- prd - Production environment
Each environment has its own AWS account and configuration.
The @leanstacks/lambda-utils package is a TypeScript utility library for AWS Lambda functions. It provides pre-configured logging, API response formatting, configuration validation, and AWS SDK clients—reducing boilerplate and promoting best practices within Node.js Lambda functions.
Several of the Lambda Utils are used in the Lambda Starter application. You are encouraged to use the Lambda Utils library in your project or, if you want to maintain the source code yourself, you may fork the repo or copy only the code you need into your project.
Learn more about the Lambda Utils with these resources...
This project implements the Simple Web Service serverless microservice pattern. The Serverless Microservice Patterns repository provides a comprehensive collection of additional patterns and examples, including:
- Simple Web Service: A basic serverless web service pattern using API Gateway, Lambda, and DynamoDB.
- Gatekeeper: Adds an Auth microservice to authenticate and authorize API requests.
- Internal API: Facilitates synchronous, internal microservice-to-microservice integration without API Gateway exposure.
- Internal Handoff: Enables asynchronous microservice-to-microservice communication.
- Publish Subscribe: Demonstrates event-driven architecture using SNS topics and SQS queues for loose coupling.
- Queue-Based Load Leveling: Uses a message queue as a buffer to decouple producers from consumers and smooth demand spikes.
Each pattern is implemented as a standalone project with practical examples and reference implementations for building scalable, event-driven microservices on AWS.
This project is licensed under the MIT License - see the LICENSE file for details.