@wmakeev/lambda-node-standard-http-response
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

lambda-node-standard-http-response

npm

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) function
  • options.debug: boolean - if true, then debug option will pass to wrappedlambda-node-standard-response handler
  • options.isBase64Encoded: boolean - if true, then body content shoud equal to standard response result field

returns:

You handler wrapped in AWS Lambda standard handler style function function(event, context, cb)

Dependents (0)

Package Sidebar

Install

npm i @wmakeev/lambda-node-standard-http-response

Weekly Downloads

0

Version

2.0.2

License

ISC

Last publish

Collaborators

  • wmakeev