1. create a folder in your local machine called nodejs
  2. put your "shared" logic in that folder like /nodejs/shared.js
  3. you can zip this nodejs folder and upload as a layer
  4. in your lambda code require the shared.js as const shared = require('/opt/nodejs/shared.js')

Links:

  • Lambda layers: https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html
  • Detailed guide: https://explainexample.com/computers/aws/aws-lambda-layers-node-app
  • Using layers with SAM: https://docs.aws.amazon.com/serverlessrepo/latest/devguide/sharing-lambda-layers.html
Answer from Sándor Bakos on Stack Overflow
🌐
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
Create the layer in Lambda. Add the layer to your functions. ... To create a layer, bundle your packages into a .zip file archive that meets the following requirements: Build the layer using the same Node.js version that you plan to use for the Lambda function.
🌐
Medium
medium.com › @anuragchitti1103 › creating-lambda-layer-with-node-js-6a5ecd7c7553
Creating Lambda Layer with Node.js | by Anurag Chitti | Medium
July 18, 2023 - - Click on “Create layer” provide a name and description and select the runtime as “Node.js”. - Upload the ZIP file you created in step 1 as the layer package. ... For example, if you attached the `lodash` package layer, you can import ...
Discussions

node.js - How to share my own custom fucntions on AWS lambda nodejs - Stack Overflow
I Currently have a project in AWS with several lambda functions, most of the functions in NodeJS, I want to know if is there a way to create a lambda layer with my own code functions that I use in different lambdas without publish it in npm, I already search in old questions in stack question-1 ... More on stackoverflow.com
🌐 stackoverflow.com
node.js - Use custom Layers in NodeJS lambda - Stack Overflow
I am using the serverless framework ... of my lambda and layers. ... 05-24 07:12PM ~/poc $ ls README.md webapp-display webapp-layers webapp-money-movements webapp-signup · I have my layers in a seperate folder with this folder structure: 05-24 07:09PM ~/poc/webapp-layers $ ls index.js layers node_modules ... More on stackoverflow.com
🌐 stackoverflow.com
How to upload a Lambda function with Node.js SDKs and dependencies?
Try this search for more information on this topic. Comments, questions or suggestions regarding this autoresponse? Please send them here . I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/aws
6
3
February 1, 2025
How to use Sharp in AWS Lambda function? I keep getting errors. (node.js, for image resizing)
Can you provide details about how you’re building and deploying the function and layer. Most likely is that it’s a problem with your build step. More on reddit.com
🌐 r/aws
10
6
September 15, 2024
🌐
DEV Community
dev.to › afrazkhan › how-to-setup-aws-lambda-layers-nodejs-182
How to setup AWS Lambda Layers (Nodejs) - DEV Community
April 28, 2024 - You can also install a linked custom module in any other node module by running command npm link { custom-module-name }. To create lambda layer for nodejs code, we need to creat a build for our code.
🌐
Danielleheberling
danielleheberling.xyz › blog › lambda-layer-example
Create Your Own Lambda Layer with NodeJS | Danielle's Blog
January 22, 2020 - const palindrome = require("/opt/nodejs/palindrome") exports.handler = async (event, context) => { // Log the event argument for debugging and for use in local development. console.log(JSON.stringify(event, undefined, 2)) const words = "This string should be reversed" const response = palindrome(words) return { statusCode: 200, headers: {}, response: JSON.stringify(response), } } The important thing to note here is the first line where we require from /opt/nodejs, otherwise you can use your library like you normally would when developing outside of Lambda. Once deployed, go ahead and invoke the function. You should see the original string reversed in the function response. Check out the full code example in this repo. All of the official documentation from AWS about Lambda layers can be found here.
🌐
Medium
medium.com › @anjanava.biswas › nodejs-runtime-environment-with-aws-lambda-layers-f3914613e20e
NodeJS Runtime Environment with AWS Lambda Layers | by Anjan Biswas | Medium
February 25, 2020 - Log on to your AWS Console, and navigate over to Lambda Console. Click on Layers on the left panel, and then “Create Layer”. ... The next section is pretty self explanatory. Give your Layer a name, description and upload your nodejs zip ...
🌐
CloudZenia Blogs
cloudzenia.com › home › blogs › how to use lambda layer for nodejs npm modules
Mastering Lambda Layer: Node.js NPM Module Integration | CloudZenia
June 9, 2025 - Now, let’s break down the steps to add those Node modules as Lambda Layers · Run npm install for each module you want to include, or if you have the module names mentioned in the package.json file, then run “npm i”. This will create a ...
Find elsewhere
🌐
Explainexample
explainexample.com › computers › aws › aws-lambda-layers-node-app
Use AWS Lambda layers for your Node.js app
In this section, we will set up ... this section, you will be in a position to create your own serverless Nodejs app. Step 1 - Create a new Lamda Layer using the AWS Lambda console....
🌐
Lightrun
docs.lightrun.com › lambda › nodejs-layers
Install Lightrun with Lambda Layers - Lightrun Documentation
September 6, 2023 - Click Create Layer. Specify a name for the new Lambda Layer. Upload the generated layers.zip file. Select the compatible architecture and runtime for your .zip file (we will be using the x86_64 architecture and Node.js 24.x as our preferred ...
🌐
LinkedIn
linkedin.com › pulse › aws-lambda-how-create-nodejs-layer-axios-michel-bluteau-6jkqe
AWS Lambda: How to create a nodejs layer for axios
February 24, 2024 - We can see that the axios.zip layer file has been created. It includes the node_modules subdirectory with the required dependencies for axios. Now we just need to import the axios layer into Lambda so we can reference it using its ARN from within nodejs Lambda Functions.
🌐
Plain English
plainenglish.io › home › blog › nodejs › using layers on aws lambda — node.js
Using Layers on AWS Lambda — Node.js
December 30, 2021 - ... Make a zip file of nodejs folder. ... That's it. Now we can upload this to Lambda. Expand the left navigation panel of the Lambda console. Select Layers and click on Create Layer.
🌐
GitHub
github.com › aws-samples › aws-lambda-layers-aws-sam-examples
GitHub - aws-samples/aws-lambda-layers-aws-sam-examples: This example application shows how to build AWS Lambda Layers using Node.js and the AWS Serverless Application Model. Questions? @jbesw. · GitHub
January 12, 2026 - This example application shows how to build AWS Lambda Layers using Node.js and the AWS Serverless Application Model. Questions? @jbesw. - aws-samples/aws-lambda-layers-aws-sam-examples
Starred by 29 users
Forked by 15 users
🌐
GitHub
github.com › tobilg › nodejs-lambda-layer-builder
GitHub - tobilg/nodejs-lambda-layer-builder: Build custom AWS Lambda layers for Node
Builds either a zip file or a raw directory strucutre (e.g. if you want to use frameworks like Serverless for packaging) containing Node dependencies and places the libraries into the proper directory structure for lambda layers · Ensures compiled libraries are compatible with Lambda environment by using the lambci/lambda Docker container that mimics the lambda runtime environment · Allows specifying AWS Lambda supported Node versions: 8.10, 10.x and 12.x · Automatically searches for package.json file in several locations:
Author   tobilg
🌐
1 Billion Technology
1billiontech.com › blog_Lambda_layers_with_NodeJS.php
Lambda layers with NodeJS
1 Billion Tech uses innovative acceleration to create and deliver best in class services.
🌐
freeCodeCamp
freecodecamp.org › news › lambda-layers-2f80b9211318
How to build and use a Layer for your AWS Lambdas
January 16, 2019 - I like to have all my layers in a folder next to my Lambdas folder. We can create a new layer folder called DemoLayer which needs to have a folder for the runtime that it is going to use. For this example, we are going to use nodejs, so we create that folder. ... Using our terminal, we can navigate to the DemoLayer folder and initialize NPM. ... Accept all the default values in the NPM setup, and you’ll have the package.json ...
🌐
Medium
medium.com › appgambit › part-1-getting-started-with-aws-lambda-layers-1677a6b006
Part 1 — Getting started with AWS Lambda Layers | by Dhaval Nagar | AppGambit | Medium
May 31, 2019 - Just create a directory with package.json and install the moment.js library. $ mkdir momentjs-layer && cd momentjs-layer $ npm init -y $ npm install --save moment · Now that you have the layer setup ready, we will have to create a bundle which ...
🌐
AWS re:Post
repost.aws › knowledge-center › lambda-layer-aws-sdk-latest-version
Integrate the AWS SDK for JavaScript into a Node.js Lambda function | AWS re:Post
April 28, 2025 - Choose the Custom Layers dropdown list, and then choose your custom layer. Choose Add. Complete the steps in the (Optional) Confirm the AWS SDK version that your function uses section to invoke your function. The function returns the version of the AWS SDK that it uses. Best practices for working with AWS Lambda functions · How do I build a Lambda deployment package for Node.js? How can I create a layer for my Lambda Python function?
🌐
AWS Amplify
docs.amplify.aws › gen1 › javascript › build-a-backend › functions › layers
Reuse code and assets using layers - JavaScript - AWS Amplify Gen 1 Documentation
April 29, 2024 - We recommend you to create a dev environment and test the functions inside the AWS Lambda console. The general workflow breaks down into the following steps: ... Next, you'll be guided through a workflow to provide a layer name, and select a supported runtime. Currently Amplify CLI provides NodeJS or Python runtime support for layers.
🌐
GitHub
github.com › nsriram › aws-lambda-layer-example
GitHub - nsriram/aws-lambda-layer-example: aws lambda layer example
December 5, 2018 - This article outlines the steps involved in building a node js lambda using lambda layers for library dependencies, using AWS CLI.
Author   nsriram