You cannot load NPM modules without uploading a .zip file, but you can actually get this process down to two quick command lines.

Here's how:

  1. Put your Lambda function file(s) in a separate directory. This is because you install npm packages locally for Lambda and you want to be able to isolate and test what you will upload to Lambda.

  2. Install your NPM packages locally with npm install packageName while you're in your separate Lambda directory you created in step #1.

  3. Make sure your function works when running locally: node lambdaFunc.js (you can simply comment out the two export.handler lines in your code to adapt your code to run with Node locally).

  4. Go to the Lambda's directory and compress the contents, make sure not to include the directory itself.

    zip -r lambdaFunc.zip .
    
  5. If you have the aws-cli installed, which I suggest having if you want to make your life easier, you can now enter this command:

    aws lambda update-function-code --function-name lambdaFunc \
    --zip-file fileb://~/path/to/your/lambdaFunc.zip
    

    (no quotes around the lambdaFunc part above in case you wonder as I did)

  6. Now you can click test in the Lambda console.

  7. I suggest adding a short alias for both of the above commands. Here's what I have in mine for the much longer Lambda update command:

    alias up="aws lambda update-function-code --function-name lambdaFunc \
    --zip-file fileb://~/path/to/your/lambdaFunc.zip"
    
Answer from JohnAllen on Stack Overflow
🌐
npm
npmjs.com › package › aws-lambda
aws-lambda - npm
Latest version: 1.0.7, last published: 4 years ago. Start using aws-lambda in your project by running `npm i aws-lambda`. There are 924 other projects in the npm registry using aws-lambda.
      » npm install aws-lambda
    
Published   Nov 07, 2021
Version   1.0.7
Author   Adrian Praja
🌐
npm
npmjs.com › package › @types › aws-lambda
@types/aws-lambda - npm
February 26, 2026 - TypeScript definitions for aws-lambda. Latest version: 8.10.161, last published: a month ago. Start using @types/aws-lambda in your project by running `npm i @types/aws-lambda`. There are 921 other projects in the npm registry using @types/aws-lambda.
      » npm install @types/aws-lambda
    
Top answer
1 of 10
319

You cannot load NPM modules without uploading a .zip file, but you can actually get this process down to two quick command lines.

Here's how:

  1. Put your Lambda function file(s) in a separate directory. This is because you install npm packages locally for Lambda and you want to be able to isolate and test what you will upload to Lambda.

  2. Install your NPM packages locally with npm install packageName while you're in your separate Lambda directory you created in step #1.

  3. Make sure your function works when running locally: node lambdaFunc.js (you can simply comment out the two export.handler lines in your code to adapt your code to run with Node locally).

  4. Go to the Lambda's directory and compress the contents, make sure not to include the directory itself.

    zip -r lambdaFunc.zip .
    
  5. If you have the aws-cli installed, which I suggest having if you want to make your life easier, you can now enter this command:

    aws lambda update-function-code --function-name lambdaFunc \
    --zip-file fileb://~/path/to/your/lambdaFunc.zip
    

    (no quotes around the lambdaFunc part above in case you wonder as I did)

  6. Now you can click test in the Lambda console.

  7. I suggest adding a short alias for both of the above commands. Here's what I have in mine for the much longer Lambda update command:

    alias up="aws lambda update-function-code --function-name lambdaFunc \
    --zip-file fileb://~/path/to/your/lambdaFunc.zip"
    
2 of 10
68

A .zip file is required in order to include npm modules in Lambda. And you really shouldn't be using the Lambda web editor for much of anything- as with any production code, you should be developing locally, committing to git, etc.

MY FLOW:

1) My Lambda functions are usually helper utilities for a larger project, so I create a /aws/lambdas directory within that to house them.

2) Each individual lambda directory contains an index.js file containing the function code, a package.json file defining dependencies, and a /node_modules subdirectory. (The package.json file is not used by Lambda, it's just so we can locally run the npm install command.)

package.json:

{
  "name": "my_lambda",
  "dependencies": {
    "svg2png": "^4.1.1"
  }
}

3) I .gitignore all node_modules directories and .zip files so that the files generated from npm installs and zipping won't clutter our repo.

.gitignore:

# Ignore node_modules
**/node_modules

# Ignore any zip files
*.zip

4) I run npm install from within the directory to install modules, and develop/test the function locally.

5) I .zip the lambda directory and upload it via the console.

(IMPORTANT: Do not use Mac's 'compress' utility from Finder to zip the file! You must run zip from the CLI from within the root of the directory- see here)

zip -r ../yourfilename.zip * 

NOTE:

You might run into problems if you install the node modules locally on your Mac, as some platform-specific modules may fail when deployed to Lambda's Linux-based environment. (See https://stackoverflow.com/a/29994851/165673)

The solution is to compile the modules on an EC2 instance launched from the AMI that corresponds with the Lambda Node.js runtime you're using (See this list of Lambda runtimes and their respective AMIs).


See also AWS Lambda Deployment Package in Node.js - AWS Lambda

🌐
AWS re:Post
repost.aws › knowledge-center › lambda-deployment-package-nodejs
Build a Lambda deployment package for Node.js | AWS re:Post
October 11, 2022 - Note: If you receive errors when ... recent AWS CLI version. Install dependencies to the function project folder · Note: Most Node.js modules are platform-independent, but some are compiled against specific operating system environments. Lambda runs under a Linux environment. When installing modules with npm, it's a best ...
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › deploy node.js lambda functions with .zip file archives
Deploy Node.js Lambda functions with .zip file archives - AWS Lambda
Under the AWS shared responsibility model, you are responsible for the management of any dependencies in your functions' deployment packages. This includes applying updates and security patches. To update dependencies in your function's deployment package, first create a new .zip file and then upload it to Lambda.
🌐
npm
npmjs.com › package › node-lambda
node-lambda - npm
$ npx node-lambda@latest package --help Usage: node-lambda package|zip [options] Create zipped package for Amazon Lambda deployment Options: --packageManager [PACKAGE_MANAGER] Package manager used to install dependencies (default: "npm", options: "npm", "yarn") -A, --packageDirectory [PACKAGE_DIRECTORY] Local Package Directory -I, --dockerImage [DOCKER_IMAGE] Docker image for npm ci (default: "") -n, --functionName [AWS_FUNCTION_NAME] Lambda FunctionName (default: "node-lambda") -H, --handler [AWS_HANDLER] Lambda Handler {index.handler} (default: "index.handler") -e, --environment [AWS_ENVIRONMENT] Choose environment {dev, staging, production} (default: "") -x, --excludeGlobs [EXCLUDE_GLOBS] Space-separated glob pattern(s) for additional exclude files (e.g.
      » npm install node-lambda
    
Published   Jan 08, 2024
Version   1.3.0
Author   motdotla
Find elsewhere
🌐
npm
npmjs.com › package › @aws-sdk › client-lambda
@aws-sdk/client-lambda - npm
3 weeks ago - Latest version: 3.1023.0, last published: 8 hours ago. Start using @aws-sdk/client-lambda in your project by running `npm i @aws-sdk/client-lambda`. There are 1213 other projects in the npm registry using @aws-sdk/client-lambda.
      » npm install @aws-sdk/client-lambda
    
Published   Apr 02, 2026
Version   3.1023.0
Author   AWS SDK for JavaScript Team
🌐
AWS
aws.amazon.com › blogs › compute › nodejs-packages-in-lambda
Using Packages and Native nodejs Modules in AWS Lambda | Amazon Web Services
June 9, 2022 - This is just for illustration; the current version of the AWS SDK is pre-installed in Lambda, but you could use this technique to load other pre-built JavaScript packages or if you actually needed an earlier version of the AWS SDK for compatibility reasons. $ npm install --prefix=~/lambdaTestFunction aws-sdk aws-sdk@2.0.27 node_modules/aws-sdk ├── xmlbuilder@0.4.2 └── xml2js@0.2.6 (sax@0.4.2) $ ls node_modules aws-sdk
🌐
npm
npmjs.com › package › @aws-cdk › aws-lambda-nodejs
@aws-cdk/aws-lambda-nodejs - npm
The CDK Construct Library for AWS Lambda in Node.js. Latest version: 1.204.0, last published: 3 years ago. Start using @aws-cdk/aws-lambda-nodejs in your project by running `npm i @aws-cdk/aws-lambda-nodejs`. There are 79 other projects in the npm registry using @aws-cdk/aws-lambda-nodejs.
      » npm install @aws-cdk/aws-lambda-nodejs
    
Published   Jun 19, 2023
Version   1.204.0
Author   Amazon Web Services
🌐
npm
npmjs.com › package › lambda-api
lambda-api - npm
This will allow the freezing of connections and will prevent Lambda from hanging on open connections. See here for more information. An index.d.ts declaration file has been included for use with your TypeScript projects (thanks @hassankhan). Please feel free to make suggestions and contributions to keep this up-to-date with future releases. ... // import AWS Lambda types import { APIGatewayEvent, Context } from 'aws-lambda'; // import Lambda API default function import createAPI from 'lambda-api'; // instantiate framework const api = createAPI(); // Define a route api.get('/status', async (req, res) => { return { status: 'ok' }; }); // Declare your Lambda handler exports.run = async (event: APIGatewayEvent, context: Context) => { // Run the request return await api.run(event, context); };
      » npm install lambda-api
    
Published   Apr 05, 2025
Version   1.2.0
Author   Jeremy Daly
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js
Building Lambda functions with Node.js - AWS Lambda
You can run JavaScript code with Node.js in AWS Lambda. Lambda provides runtimes for Node.js that run your code to process events. Your code runs in an environment that includes the AWS SDK for JavaScript, with credentials from an AWS Identity and Access Management (IAM) role that you manage.
🌐
npm
npmjs.com › package › node-aws-lambda
node-aws-lambda - npm
A module help you automate AWS lambda function deployment.. Latest version: 0.1.8, last published: 9 years ago. Start using node-aws-lambda in your project by running `npm i node-aws-lambda`. There are 7 other projects in the npm registry using node-aws-lambda.
      » npm install node-aws-lambda
    
Published   Mar 31, 2016
Version   0.1.8
Author   Pengchao Wang
🌐
GeeksforGeeks
geeksforgeeks.org › devops › deploying-npm-modules-in-aws-lambda
Deploying NPM Modules in AWS Lambda - GeeksforGeeks
July 23, 2025 - This basically consists of setting up your Node.js environment, installing all required modules, packaging your application code along with its dependencies, and then deploying it into AWS Lambda. In this guide, we will walk you through the steps to effectively package and deploy NPM modules in AWS Lambda, allowing you to harness the full power of your Node.js applications within a serverless environment.
🌐
npm
npmjs.com › package › aws-lambda-toolkit
aws-lambda-toolkit - npm
August 10, 2017 - A small library of AWS lambda tools for easier lambda development and deployment.. Latest version: 0.4.0, last published: 9 years ago. Start using aws-lambda-toolkit in your project by running `npm i aws-lambda-toolkit`. There are no other projects ...
      » npm install aws-lambda-toolkit
    
Published   Aug 10, 2017
Version   0.4.0
Author   CID10
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › working with layers for node.js lambda functions
Working with layers for Node.js Lambda functions - AWS Lambda
The packages in your layer must be compatible with Linux. Lambda functions run on Amazon Linux. You can create layers that contain either third-party Node.js libraries installed with npm (such as axios or lodash) or your own JavaScript modules.
🌐
Bobby Hadz
bobbyhadz.com › blog › aws-lambda-use-npm-modules
How to use npm modules in AWS Lambda | bobbyhadz
February 26, 2024 - Open your terminal in the layers/date-fns/nodejs directory and install your npm modules: ... Open your terminal in the layers/date-fns directory and zip the contents. When the zip archive is extracted, the nodejs/node_modules directory structure ...
🌐
Amazon Web Services
docs.aws.amazon.com › aws lambda › developer guide › building lambda functions with node.js › define lambda function handler in node.js
Define Lambda function handler in Node.js - AWS Lambda
Only rely on the runtime-provided SDK when you can't include additional packages (for example, when using the Lambda console code editor or inline code in an AWS CloudFormation template). To add SDK dependencies to your function, use the npm install command for the specific SDK clients that ...
🌐
npm
npmjs.com › package › lambda-local
lambda-local - npm
April 13, 2024 - --esm (optional) Load lambda function as ECMAScript module. -r, --region <aws region> (optional) Sets the AWS region, defaults to us-east-1.
      » npm install lambda-local
    
Published   Apr 13, 2024
Version   2.2.0
Author   ashiina