λ-dev
Develop and Bundle Your Lambda Functions With Ease.
Installation
npm install --save-dev lambda-dev
yarn add --dev lambda-dev
Usage
Development
Use lambda-dev
to develop lambda functions locally. lambda-dev serve
starts an Express server that proxies http requests to your lambda functions. They are transpiled with @babel/core and @babel/preset-env, with the node target set to --node [target]
(default 6.10
). This is done through webpack with the help of babel-loader.
lambda-dev serve --helplambda-dev serve src/functions --node 8.10 --port 9000 --basePath /lambda
Now a given function src/functions/test.js
will be invoked with requests to http://localhost:9000/lambda/test
.
Build
lambda-dev build --helplambda-dev serve src/functions build/functions --node 8.10
Bundled functions will be at build/functions
.
Custom Webpack configuration
It is possible to supply a custom Webpack configuration for serving and building your Lambda functions:
lambda-dev serve src/functions --webpack-config ./my-webpack.config.js
where the default export of my-webpack.config.js
should be either and object or a function. If it's an object, it will be merged with the default configuration using merge.smart
from webpack-merge. If it's a function, it will receive the default configuration as its argument and should return a full valid configuration.
Custom babel configuration
It's not possible to directly supply a custom babel configuration, but you can override the webpack configuration's babel-loader options:
const myBabelOptions = ; moduleexports = module: rules: test: /\.js$/ use: loader: require options: babelrc: false options: myBabelOptions ;
Lambda Function Specification
Read the official docs
Lambda functions should export a handler
function that receives the following arguments:
; type Event = path: Requestpath httpMethod: Requestmethod queryStringParameters: Requestquery headers: Requestheaders body: Requestbody; type Context = {} // Empty with `lambda-dev serve` exportshandler: ;