@wmakeev/lambda-node-standard-response
v2.0.1
Published
Standard response spec implementation for aws lambda node functions
Downloads
2
Readme
lambda-node-standard-response
Standard response spec implementation for aws lambda node functions
Installation
$ npm install @wmakeev/lambda-node-standard-response
Usage
Example of aws lambda function code:
const standardResponse = require('@wmakeev/lambda-node-standard-response')
function doStuff (ev) {
return ev.value
}
function doStuffAsync (ev) {
return Promise.resolve(ev.value)
}
exports.default = standardResponse(function (ev, ctx) {
return ev.async ? doStuffAsync(ev) : doStuff(ev)
}, { debug: true })
doStuff
can be sync or async (in case of async it should return Promise
)
Lambda event:
{
"async": "true",
"value": "Hello world!"
}
Lambda response (same in sync and async cases):
{
"ok": true,
"result": "Hello world!",
"format": "2.0"
}
Lambda response in the case standardResponse
caught an error:
{
"ok": false,
"description": "Some error message", // equal to error.message field or 'Unknown error' (if handler returns not Error type without not empty message string field or string type error)
"name": "Error", // equal to error.name
"code": "some code", // equal to error.code
"stack": ['stack trace lines'], // specified if `options.debug` is true
"format": "2.0"
}
API
standardResponse(handler: function(ev, context), options: object): function(event, context, cb)
handler
- sync or async (returns Promise) functionoptions.debug
-boolean
value (iftrue
, then error response will includestack
property)
returns:
You handler
wrapped in AWS Lambda standard handler style function function(event, context, cb)