lambda-build

raw JSON →
1.0.6 verified Fri May 01 auth: no javascript

Bundle TypeScript/JavaScript Node.js Lambda handlers into a deployable zip using esbuild. Current version: 1.0.6. Provides CLI commands (`archive`, `upload`) and programmatic API (`build`, `buildAndUpload`). Supports custom entry files, excluding external modules (e.g., layers), and generating esbuild metafiles for bundle analysis. Differentiates from similar tools by focusing solely on Lambda deployment with zero-config defaults and AWS CLI integration. Ships with TypeScript declarations. Lightweight alternative to serverless-webpack or AWS SAM.

error Error: esbuild is not installed. Please install it manually: npm i -D esbuild
cause lambda-build depends on esbuild but does not automatically install it.
fix
Install esbuild as a dev dependency: npm i -D esbuild
error Error: Cannot find module 'aws-sdk'
cause AWS SDK is excluded by default but not provided in the runtime layer.
fix
Either add 'aws-sdk' to external array only if you have it in a layer, or bundle it by removing it from external.
error Error: The 'entry' option is required.
cause You called `build` without specifying an entry file.
fix
Pass an entry option pointing to your handler file, e.g., entry: 'src/handler.ts'.
error Error: ENOENT: no such file or directory, open 'src/index.ts'
cause The default entry file (index.js or index.ts) does not exist in the current directory.
fix
Use -e to specify a custom entry file, or create a default index file.
gotcha The `upload` command requires the AWS CLI to be installed and configured locally.
fix Ensure AWS CLI is set up via `aws configure` before using `upload`.
gotcha External modules declared via `-x` or `external` option must be available in the Lambda runtime environment (e.g., via layers or Lambda provided SDK).
fix Verify that excluded dependencies are present as layers or included in the Lambda runtime.
deprecated No deprecated features known at this version.
fix None.
breaking Major version 1.x introduced esbuild as the bundler. If migrating from a previous major version that used a different bundler, configuration may differ.
fix Update to use esbuild options; see documentation for changes.
npm install lambda-build
yarn add lambda-build
pnpm add lambda-build

Shows programmatic usage: bundle a TypeScript Lambda handler and create a zip archive with metafile.

import { build } from 'lambda-build';

async function quickstart() {
  const result = await build({
    entry: 'src/handler.ts',
    external: ['aws-sdk'],
    metafile: true,
  });
  console.log('Archive size:', result.archiveSize);
  // result.archive is a Buffer of the zip
}

quickstart().catch(console.error);