Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
lambda-build
✓ npx lambda-build --function=path/to/your/lambda --archive=output.zip
✗ import { lambdaBuild } from 'aws-lambda-build'
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.
Function Path Argument
✓ lambda-build -f path/to/your/function
✗ lambda-build path/to/your/function
The function directory path must be specified using the `--function` or `-f` flag.
Archive Name Argument
✓ lambda-build --function=... --archive=my-function.zip
✗ lambda-build --function=... -n my-function.zip
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.
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.
const { exec } = require('child_process');
const path = require('path');
// Create a dummy Lambda function directory for demonstration
const functionName = 'MyTestLambda';
const functionPath = path.resolve(__dirname, functionName);
require('fs').mkdirSync(functionPath, { recursive: true });
require('fs').writeFileSync(path.join(functionPath, 'index.js'), `
exports.handler = async (event) => {
console.log('Received event:', JSON.stringify(event, null, 2));
return { statusCode: 200, body: JSON.stringify('Hello from ${functionName}!') };
};
`);
require('fs').writeFileSync(path.join(functionPath, 'package.json'), `
{
"name": "${functionName.toLowerCase()}",
"version": "1.0.0",
"description": "A simple Lambda function",
"main": "index.js",
"dependencies": {
"lodash": "^4.17.21"
}
}
`);
const archiveName = `${functionName}.zip`;
console.log(`Building Lambda function from: ${functionPath}`);
console.log(`Output archive: ${archiveName}`);
// Execute the aws-lambda-build CLI tool
// Using 'npx' ensures the tool is available without global installation.
exec(`npx aws-lambda-build --function=${functionPath} --archive=${archiveName} --verbose`, (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
console.error(`stderr: ${stderr}`);
return;
}
console.log(`stdout: ${stdout}`);
console.log('Lambda build completed successfully!');
console.log(`You can now upload ${archiveName} to AWS Lambda.`);
// Clean up the dummy function directory and zip file
require('fs').rmSync(functionPath, { recursive: true, force: true });
require('fs').rmSync(archiveName, { force: true });
console.log('Cleaned up dummy function and archive.');
});
aws-lambda-build --version
Errors
Common errors & fixes
lambda-build: command not found
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.
fixInstall the package globally: `npm install -g aws-lambda-build`, or execute it via `npx`: `npx aws-lambda-build [arguments]`.
Error: Function directory not found: [your/path]
The path provided to the `--function` (or `-f`) argument does not point to an existing directory containing your Lambda function code.
fixVerify that the `--function` path is correct and absolute, or relative to the directory where you are executing `lambda-build`.
npm ERR! code ENOSPC
During the internal `npm install` step, the system ran out of disk space, preventing dependencies from being fully installed or extracted.
fixFree up disk space on the machine where the build process is running.
Audit
Dependencies
archiverrequiredUsed for creating the .zip archive of the Lambda function.