apigateway-http-request

1.1.2 • Public • Published

apigateway-http-request Build Status

For use with AWS Lambda. Parses an incoming API Gateway event into a more familiar structure similar to an express req.

Getting started

Here's an example AWS Lambda function that echos back incoming request body.

import { fromIncomingEvent, ApigatewayHttpSuccessResponse } from 'apigateway-http-request'
 
export default { 
  handler(event, context, callback) {
    let req = fromIncomingEvent(event); // returns an ApigatewayHttpRequest
    console.log(req);
    // optionally use included response
    let body        = { timestamp: Date.now(), echo: req.body };
    let statusCode  = 200;
    let headers     = { 'Some-Header': 'hi' };
    // if no requestId is supplied one will be generated
    // let requestId   = 'generated request id or one supplied by aws';
    let res = new ApigatewayHttpSuccessResponse(body, statusCode, headers, requestId);
    callback(null, res.format());
  }
};

Readme

Keywords

none

Package Sidebar

Install

npm i apigateway-http-request

Weekly Downloads

1

Version

1.1.2

License

MIT

Last publish

Collaborators

  • cmawhorter