Creating Lambda layers for common functions
To save on repetitive code in your Lambda functions, you can define a custom Lambda Layer to add to functions where you need to use the same code. You can do this in the same manner as creating a normal Node.js project, however:
- Your own code needs to be in the node_modules/your-module-name folder
- A specific folder structure needs to be present for Lambda to work properly
An example folder structure for the dc-lambda-common layer is below:
Be careful to move your own code into another folder before running npm install to get your other project dependencies, as npm will remove your code from the node_modules folder if it's in there.