{"id":15526,"library":"aws-lambda-bundler","title":"AWS Lambda Bundler","description":"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.","status":"abandoned","version":"1.0.12","language":"javascript","source_language":"en","source_url":null,"tags":["javascript","aws","lambda","hash","bundle","zip"],"install":[{"cmd":"npm install aws-lambda-bundler","lang":"bash","label":"npm"},{"cmd":"yarn add aws-lambda-bundler","lang":"bash","label":"yarn"},{"cmd":"pnpm add aws-lambda-bundler","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While the README shows CommonJS `require`, modern Node.js and TypeScript usage often prefers ES Modules. However, given the package's age, its primary API is likely CJS-first, and ESM import might not be natively supported or correctly transpiled by older versions of the tool itself. Explicit named import is correct for both CJS and ESM, assuming modern tooling can handle CJS to ESM interop.","wrong":"const bundle = require('aws-lambda-bundler').bundle;","symbol":"bundle","correct":"import { bundle } from 'aws-lambda-bundler';"},{"note":"The README excerpt suggests a named export `{ bundle }`. If there's a default export (e.g., the `bundle` function itself), it would be imported as `import bundler from 'aws-lambda-bundler';`. However, based on the provided snippet, `bundle` is a named export.","wrong":"import { default as bundler } from 'aws-lambda-bundler';","symbol":"default export","correct":"import bundler from 'aws-lambda-bundler';"}],"quickstart":{"code":"const { bundle } = require('aws-lambda-bundler');\nconst fs = require('fs');\nconst path = require('path');\n\nasync function createDummyLambdaProject() {\n  const projectDir = path.join(__dirname, 'my-lambda-project');\n  const handlerDir = path.join(projectDir, 'src');\n  const handlerFile = path.join(handlerDir, 'handler.js');\n  const packageJsonFile = path.join(projectDir, 'package.json');\n\n  if (!fs.existsSync(handlerDir)) {\n    fs.mkdirSync(handlerDir, { recursive: true });\n  }\n\n  fs.writeFileSync(handlerFile, `\nexports.handler = async (event) => {\n  console.log('Received event:', event);\n  const response = {\n    statusCode: 200,\n    body: JSON.stringify('Hello from Lambda!'),\n  };\n  return response;\n};\n`);\n\n  fs.writeFileSync(packageJsonFile, `\n{\n  \"name\": \"my-lambda-project\",\n  \"version\": \"1.0.0\",\n  \"description\": \"A dummy lambda for bundling demo\",\n  \"main\": \"src/handler.js\",\n  \"dependencies\": {\n    \"lodash\": \"^4.17.21\"\n  }\n}\n`);\n\n  console.log('Dummy lambda project created at:', projectDir);\n  return projectDir;\n}\n\nasync function runBundler() {\n  const projectPath = await createDummyLambdaProject();\n  try {\n    console.log(`\\nBundling project at ${projectPath}...`);\n    // The bundle function takes the source directory and optionally an output path.\n    // It returns a promise that resolves with the path to the created zip file.\n    const zipFilePath = await bundle(projectPath);\n    console.log(`Successfully bundled to: ${zipFilePath}`);\n    console.log('You can now inspect the contents of the zip file.');\n  } catch (error) {\n    console.error('Bundling failed:', error);\n    process.exit(1);\n  } finally {\n    // Clean up dummy project after bundling\n    fs.rmSync(projectPath, { recursive: true, force: true });\n    console.log(`Cleaned up ${projectPath}`);\n  }\n}\n\nrunBundler();\n","lang":"javascript","description":"Demonstrates programmatic bundling of a simple AWS Lambda project, including its dependencies, into a zip file, then cleans up."},"warnings":[{"fix":"Migrate to actively maintained alternatives like `@aws-cdk/aws-lambda-nodejs` (which uses `esbuild`), `serverless-esbuild`, `serverless-webpack`, or directly use `esbuild` for bundling. These tools provide better performance, security, and feature support.","message":"The package `aws-lambda-bundler` has not been updated in over six years and is considered abandoned. It may contain unpatched security vulnerabilities, lack support for modern Node.js runtimes (e.g., Node.js 18+), and not support contemporary JavaScript features or module systems (ESM). Using it in new projects is highly discouraged.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Consider using a modern bundler that allows explicit inclusion and tree-shaking of AWS SDK v3 modules (e.g., `esbuild` with `bundleAwsSDK: true` in CDK's `NodejsFunction` configuration) to fine-tune cold start performance and ensure consistent SDK versions.","message":"This bundler's primary optimization is to exclude the `aws-sdk` to reduce bundle size. While this was a common practice, newer AWS Lambda runtimes (Node.js 18+) include AWS SDK v3, and for optimal cold start performance and full control, it is often recommended to bundle the specific AWS SDK v3 modules your function uses with your deployment package, rather than relying on the runtime's provided SDK.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Evaluate modern bundlers (`esbuild`, `webpack`) that offer comprehensive support for TypeScript, ESM, and advanced optimizations like dead code elimination to significantly reduce package size and improve Lambda cold start times.","message":"This package might not correctly handle advanced bundling scenarios such as TypeScript transpilation, ES Modules (ESM) resolution, or robust tree-shaking for complex dependency graphs. Its 'simple' approach of just zipping and excluding `aws-sdk` may lead to larger-than-necessary bundles or runtime errors with modern codebases.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Run `npm install aws-lambda-bundler` or `yarn add aws-lambda-bundler` in your project directory.","cause":"The package is not installed in your project's `node_modules`.","error":"Error: Cannot find module 'aws-lambda-bundler'"},{"fix":"Ensure your Lambda function code is written in CommonJS if using older tooling, or migrate to a modern bundler (like `esbuild`) that fully supports ESM input and output for Node.js Lambda functions.","cause":"Attempting to use `require()` syntax within an ES Module (ESM) file, or the bundler itself does not correctly handle ESM input/output.","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Ensure you have appropriate write permissions for the target output directory, or specify an output path where the user has permissions (e.g., a subdirectory within your project or a temporary directory).","cause":"The user running the bundling command or script does not have write permissions to the specified output directory.","error":"Error: EACCES: permission denied, open '/path/to/output.zip'"}],"ecosystem":"npm"}