@wmakeev/lambda-node-standard-http-response
v2.0.2
Published
Standard response spec implementation for aws lambda http request handler function
Downloads
8
Maintainers
Readme
lambda-node-standard-http-response
Standard response spec implementation for aws lambda http handler function
Installation
$ npm install @wmakeev/lambda-node-standard-http-response
Usage
Example of aws lambda function code:
const standardHttpResponse = require('@wmakeev/lambda-node-standard-http-response')
function doStuff (ev) {
return ev.value
}
function doStuffAsync (ev) {
return Promise.resolve(ev.value)
}
exports.default = standardHttpResponse(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):
{
"body": "{\"format\":\"2.0\",\"ok\":true,\"result\":\"Hello world!\"}",
"isBase64Encoded": false,
"statusCode": 200
}
See more about body
format in lambda-node-standard-response module descripton
API
standardHttpResponse(handler: function(ev, context), options: object): function(event, context, cb)
handler
- sync or async (returns Promise) functionoptions.debug: boolean
- iftrue
, thendebug
option will pass to wrappedlambda-node-standard-response handleroptions.isBase64Encoded: boolean
- iftrue
, thenbody
content shoud equal to standard responseresult
field
returns:
You handler
wrapped in AWS Lambda standard handler style function function(event, context, cb)