Webpack Lambda Layer Plugin
Efficiently Package Required Node Modules for Your Lambda Layer
Webpack Lambda Layer Plugin is a tool designed to simplify the process of packaging code libraries for your Lambda functions. The plugin works by bundling the necessary node dependencies as a separate package, which can then be utilized in your Lambda Layer, providing an efficient way to share code libraries with multiple Lambda Functions.
Simultaneously, these dependencies will get externalized from your Lambda Function bundles, leading to reduced bundle sizes and improved build and deployment times.
Installation
yarn
yarn add --dev webpack-lambda-layer-plugin
npm
npm i --save-dev webpack-lambda-layer-plugin
Usage
webpack.config.js
import { LambdaLayerExternalsPlugin } from "webpack-lambda-layer-plugin";
const config: WebpackConfiguration = {
entry: "index.js",
output: {
filename: "[name]/handler.js",
path: path.resolve("dist"),
},
plugins: [
new LambdaLayerExternalsPlugin(),
],
}
export default config;
This will generate a zip archive dist/externals.zip
containing the used node_modules dependencies, alongside your Lambda Function bundles.