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 question-2, but these were not answered
Thanks for help!
CodePudding user response:
- create a folder in your local machine called nodejs
- put your "shared" logic in that folder like /nodejs/shared.js
- you can zip this nodejs folder and upload as a layer
- 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