Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws-lambda-response

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-lambda-response

A simple package for building standard responses in AWS Lambda callback functions.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

aws-lambda-response Build Status

A simple package for building standard responses in AWS Lambda callback functions to be handled by API Gateway.

Install

$ npm install --save aws-lambda-response

Why

API Gateway does not support objects as the error parameter in callbacks from Lambda, this package solves this by stringifying error and failure responses and assumes the JSON is parsed at API Gateway level.

Usage

import resp from 'aws-lambda-response';

function handler(event, context, callback) {
  callback(null, resp.success(200, { hello: "World"}));
}

export { handler };

API

The following API is based on the imported module being named resp, however it can be substituted for any name you want.

// ES6 modules
import resp from 'aws-lambda-response';

// commonJS modules
const resp = require('aws-lambda-response');

resp.success(statusCode, data)
Params
statusCode

Type: int

HTTP status code to be mapped in the API Response header

data

Type: object

Response payload.

Returns

Type: object

{
  status: "success",
  httpStatus: (int)statusCode,
  data: (obj)data
}

resp.error(statusCode, message, data)
Params
statusCode

Type: int

HTTP status code to be mapped in the API Response header

message

Type: string

Error message

data

Type: object

Any additional response data.

Returns

Type: string

Stringified object to be parsed in API Gateway output mapping.

{
  "status": "error",
  "httpStatus": "(int)statusCode",
  "message": "(string)message",
  "data": "(object)data"
}

resp.fail(statusCode, data)

Params

statusCode

Type: int

HTTP status code to be mapped in the API Response header

data

Type: object

Response data that may help explain the issue. Can be be a string if the information is better presented as one.

Returns

Type: string

Stringified object to be parsed in API Gateway output mapping.

{
  "status": "fail",
  "httpStatus": "(int)statusCode",
  "data": "(object)data"
}

License

MIT

Keywords

FAQs

Package last updated on 30 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc