AWS Lambda Function Builder

1.0.8 · maintenance · verified Sun Apr 19

`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.

Common errors

Warnings

Install

Imports

Quickstart

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.');
});

view raw JSON →