{"id":14449,"library":"aws-lambda-build","title":"AWS Lambda Function Builder","description":"`aws-lambda-build` is a lightweight command-line interface (CLI) tool designed for building and packaging AWS Lambda functions into `.zip` archives. Its core functionality involves navigating to a specified function directory, executing `npm install` to resolve dependencies, and then zipping the entire directory contents into a deployable `.zip` file. Currently at version 1.0.8, the project has seen slow but stable development, with recent updates focusing on cross-platform compatibility across Windows, Mac, and Linux, and a transition to pure Node.js for its implementation (v1.0.4). A key differentiator is its minimal footprint, explicitly stating \"no external dependencies except *archiver*\", making it a highly self-contained solution compared to more complex build systems.","status":"maintenance","version":"1.0.8","language":"javascript","source_language":"en","source_url":"https://github.com/Max-Kolodezniy/aws-lambda-build","tags":["javascript","AWS Lambda","Local build","build"],"install":[{"cmd":"npm install aws-lambda-build","lang":"bash","label":"npm"},{"cmd":"yarn add aws-lambda-build","lang":"bash","label":"yarn"},{"cmd":"pnpm add aws-lambda-build","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used for creating the .zip archive of the Lambda function.","package":"archiver","optional":false}],"imports":[{"note":"This package is primarily a CLI tool. Its main 'symbol' is the `lambda-build` executable, invoked via `npx` or a global installation. It does not export JavaScript modules for programmatic `import` or `require` in the traditional sense.","wrong":"import { lambdaBuild } from 'aws-lambda-build'","symbol":"lambda-build","correct":"npx lambda-build --function=path/to/your/lambda --archive=output.zip"},{"note":"The function directory path must be specified using the `--function` or `-f` flag.","wrong":"lambda-build path/to/your/function","symbol":"Function Path Argument","correct":"lambda-build -f path/to/your/function"},{"note":"The output archive name is specified using `--archive` or `-a`. The README shows `-n` in examples, but `package.json` CLI definition typically uses `-a` for archive.","wrong":"lambda-build --function=... -n my-function.zip","symbol":"Archive Name Argument","correct":"lambda-build --function=... --archive=my-function.zip"}],"quickstart":{"code":"const { exec } = require('child_process');\nconst path = require('path');\n\n// Create a dummy Lambda function directory for demonstration\nconst functionName = 'MyTestLambda';\nconst functionPath = path.resolve(__dirname, functionName);\nrequire('fs').mkdirSync(functionPath, { recursive: true });\nrequire('fs').writeFileSync(path.join(functionPath, 'index.js'), `\nexports.handler = async (event) => {\n  console.log('Received event:', JSON.stringify(event, null, 2));\n  return { statusCode: 200, body: JSON.stringify('Hello from ${functionName}!') };\n};\n`);\nrequire('fs').writeFileSync(path.join(functionPath, 'package.json'), `\n{\n  \"name\": \"${functionName.toLowerCase()}\",\n  \"version\": \"1.0.0\",\n  \"description\": \"A simple Lambda function\",\n  \"main\": \"index.js\",\n  \"dependencies\": {\n    \"lodash\": \"^4.17.21\"\n  }\n}\n`);\n\nconst archiveName = `${functionName}.zip`;\n\nconsole.log(`Building Lambda function from: ${functionPath}`);\nconsole.log(`Output archive: ${archiveName}`);\n\n// Execute the aws-lambda-build CLI tool\n// Using 'npx' ensures the tool is available without global installation.\nexec(`npx aws-lambda-build --function=${functionPath} --archive=${archiveName} --verbose`, (error, stdout, stderr) => {\n  if (error) {\n    console.error(`exec error: ${error}`);\n    console.error(`stderr: ${stderr}`);\n    return;\n  }\n  console.log(`stdout: ${stdout}`);\n  console.log('Lambda build completed successfully!');\n  console.log(`You can now upload ${archiveName} to AWS Lambda.`);\n  \n  // Clean up the dummy function directory and zip file\n  require('fs').rmSync(functionPath, { recursive: true, force: true });\n  require('fs').rmSync(archiveName, { force: true });\n  console.log('Cleaned up dummy function and archive.');\n});\n","lang":"typescript","description":"Demonstrates how to programmatically execute the `aws-lambda-build` CLI tool via Node.js `child_process` to package a sample Lambda function. This shows the typical workflow of using the CLI."},"warnings":[{"fix":"Use `npx aws-lambda-build ...` for one-off executions or `npm install -g aws-lambda-build` followed by `lambda-build ...` for frequent use. Do not attempt to `import` or `require` it as a module.","message":"This package is primarily a command-line interface (CLI) tool and is not designed for programmatic import as a JavaScript or TypeScript library. Its core functionality is exposed exclusively via the `lambda-build` executable.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure that a compatible version of Node.js and npm are installed and accessible in your shell or CI/CD environment.","message":"The `npm install` step performed by `aws-lambda-build` requires Node.js (>=5.0) and npm to be correctly installed and available in the system's PATH where the build command is executed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefer using consistent forward slashes (`/`) for paths, which are generally compatible across operating systems, or use Node.js `path.resolve()` when generating paths programmatically.","message":"Although the tool claims cross-platform support (since v1.0.7), inconsistencies in path separators (e.g., backslashes on Windows vs. forward slashes on Linux/macOS) can still lead to errors if not handled carefully, especially when passing paths via command-line arguments.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install the package globally: `npm install -g aws-lambda-build`, or execute it via `npx`: `npx aws-lambda-build [arguments]`.","cause":"The `aws-lambda-build` executable is not in the system's PATH, typically because the package was not installed globally or `npx` was not used.","error":"lambda-build: command not found"},{"fix":"Verify that the `--function` path is correct and absolute, or relative to the directory where you are executing `lambda-build`.","cause":"The path provided to the `--function` (or `-f`) argument does not point to an existing directory containing your Lambda function code.","error":"Error: Function directory not found: [your/path]"},{"fix":"Free up disk space on the machine where the build process is running.","cause":"During the internal `npm install` step, the system ran out of disk space, preventing dependencies from being fully installed or extracted.","error":"npm ERR! code ENOSPC"}],"ecosystem":"npm"}