Skip to content

djgrant/aws-lambda-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aws-lambda-express

Express style routing for AWS Lambda.

The library provides a similar API to Express, with the difference of being backed by Lambda's event and context objects, rather than the HTTP module.

Installation

The project is still a WIP so I have not published to NPM yet.

Usage

const Router = require("aws-lambda-express");

const router = new Router();

router.use((req, res, next) => {
  console.log(req.event);
  console.log(req.context);
  next();
});

router.use("/some/route", (req, res, next) => {
  res
    .set({ "my-header": "hello" })
    .status(200)
    .send("Hello world");
});

const handler = (event, context, cb) => {
  router
    .handle(event, context)
    .then(response => {
      cb(null, {
        body: response.body,
        headers: response.headers,
        statusCode: response.statusCode
      });
    })
    .catch(err) => {
      cb(err);
    });
};

module.exports = handler;

API

For now, please refer to the tests in test/router.test.js for a complete API reference.

Todo

  • [] HTTP methods
  • [] Docs
  • [] Publish to NPM

About

Express style routing for AWS lambda

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published