Lightweight Web Framework for AWS Lambda

1.2.0 · active · verified Sun Apr 19

lambda-api is a zero-dependency, lightweight web framework designed specifically for building serverless applications on AWS Lambda. It supports both AWS API Gateway Lambda Proxy Integration and ALB Lambda Target Support, providing a minimal yet familiar API similar to Express.js or Fastify for routing, middleware, and error handling. Optimized for the stateless, single-run execution model of Lambda, it prioritizes fast cold starts and low memory consumption by eschewing external dependencies. The package is currently at version 1.2.0, with a consistent release cadence of minor versions to introduce new features, enhance TypeScript type definitions, and resolve bugs. Its primary differentiation lies in its minimal footprint and dedicated focus on the unique demands of serverless environments, making it ideal for high-performance, cost-efficient serverless APIs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `lambda-api`, define a simple GET and POST route, and expose it as an AWS Lambda handler.

import lambdaApi from 'lambda-api';

const api = lambdaApi();

// Define a route that responds with a status object
api.get('/status', async (req, res) => {
  return { status: 'ok', timestamp: new Date().toISOString() };
});

// Define a route that handles a POST request with a body
api.post('/greet', async (req, res) => {
  const name = req.body?.name || 'Guest';
  return { message: `Hello, ${name}!` };
});

// Declare your Lambda handler function
export const handler = async (event, context) => {
  // Run the request through the lambda-api framework
  return await api.run(event, context);
};

view raw JSON →