AWS Lambda Bundler

1.0.12 · abandoned · verified Tue Apr 21

aws-lambda-bundler is a JavaScript utility designed to create zip archives for AWS Lambda function deployments. Its primary feature is the explicit exclusion of the `aws-sdk` from the bundled package, aiming to reduce the overall deployment size, as the SDK is often the largest component. The package is currently at version 1.0.12. Released over six years ago, it appears to be no longer actively maintained, with minimal updates or recent community activity. While it offers a simple command-line and programmatic interface for basic bundling, modern AWS Lambda deployment practices typically favor more advanced bundlers like `esbuild` (often integrated into AWS CDK's `NodejsFunction` or Serverless Framework) or `webpack` for their superior performance, tree-shaking capabilities, and better support for contemporary JavaScript features like TypeScript and ESM. These newer alternatives provide more granular control over dependencies and often result in smaller, more optimized bundles and improved cold start times.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates programmatic bundling of a simple AWS Lambda project, including its dependencies, into a zip file, then cleans up.

const { bundle } = require('aws-lambda-bundler');
const fs = require('fs');
const path = require('path');

async function createDummyLambdaProject() {
  const projectDir = path.join(__dirname, 'my-lambda-project');
  const handlerDir = path.join(projectDir, 'src');
  const handlerFile = path.join(handlerDir, 'handler.js');
  const packageJsonFile = path.join(projectDir, 'package.json');

  if (!fs.existsSync(handlerDir)) {
    fs.mkdirSync(handlerDir, { recursive: true });
  }

  fs.writeFileSync(handlerFile, `
exports.handler = async (event) => {
  console.log('Received event:', event);
  const response = {
    statusCode: 200,
    body: JSON.stringify('Hello from Lambda!'),
  };
  return response;
};
`);

  fs.writeFileSync(packageJsonFile, `
{
  "name": "my-lambda-project",
  "version": "1.0.0",
  "description": "A dummy lambda for bundling demo",
  "main": "src/handler.js",
  "dependencies": {
    "lodash": "^4.17.21"
  }
}
`);

  console.log('Dummy lambda project created at:', projectDir);
  return projectDir;
}

async function runBundler() {
  const projectPath = await createDummyLambdaProject();
  try {
    console.log(`\nBundling project at ${projectPath}...`);
    // The bundle function takes the source directory and optionally an output path.
    // It returns a promise that resolves with the path to the created zip file.
    const zipFilePath = await bundle(projectPath);
    console.log(`Successfully bundled to: ${zipFilePath}`);
    console.log('You can now inspect the contents of the zip file.');
  } catch (error) {
    console.error('Bundling failed:', error);
    process.exit(1);
  } finally {
    // Clean up dummy project after bundling
    fs.rmSync(projectPath, { recursive: true, force: true });
    console.log(`Cleaned up ${projectPath}`);
  }
}

runBundler();

view raw JSON →