vamtiger-serve-lambda
v0.0.21
Published
A utility to serve aws lambda projects locally for integration testing.
Downloads
4
Maintainers
Readme
VAMTIGER Serve Lambda
A utility to serve aws lambda projects for local debugging and integration testing. It simulates deployment, and can be used across multiple labmda projects.
Installation
VAMTIGER Serve Lambda can be installed using npm or yarn:
npm i --save-dev vamtiger-serve-lambda # local
npm i --global vamtiger-serve-lambda # global
or
yarn add --dev vamtiger-serve-lambda #local
yarn global vamtiger-serve-lambda #global
Usage
VAMTIGER Serve Lambda can be used to respond to requests inside lambda project:
# path/to/file.js
# export default lambda(event, context, callback)...
vamtiger-serve-lambda --port 8888 --path path/to/file.default
When using export default, the --path will be inferred from package.json:
{
//...
//...
"main": "path/to/file"
//...
//...
}
vamtiger-serve-lambda --port 8888
A custom Request Handler can also be defined using the --handleRequest or -H option:
vamtiger-serve-lambda --port 8888 -H path/to/custom/request/handler
VAMTIGER Serve Lambda can also be defined as an npm script:
// package.json
{
//..
"main": "path/to/file",
"scripts": {
"serve": "vamtiger-serve-lambda -p 8888" // assuming default export of main
}
//..
}
The lambda function can then be served by running:
npm run serve
It can also be debugged in Visual Studio Code:
// launch.json
{
"version": "0.2.0",
"configurations":[
{
"type": "node",
"request": "launch",
"name": "vamtiger-serve-lambda",
"program": "${workspaceRoot}/node_modules/vamtiger-serve-lambda/build/bin",
"args": [
"-p",
"8888"
]
}
]
}
All HTTP requests made will then invoke the locally served lambda function:
const post = require('request-promise');
const params = {
url: 'http://localhost:8888',
body: {
hello: 'world'
},
json: true
};
post(params)
.then(handleResult)
.catch(handleError);