Skip to content

Use Express, hapi, or other NodeJS web frameworks on API Gateway and Lambda

License

Notifications You must be signed in to change notification settings

nddeluca/lambda-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lambda-http

Use Express, hapi, or other NodeJS web frameworks on API Gateway and Lambda

Inspired by https://github.com/awslabs/aws-serverless-express

Usage

npm install lambda-http

Express Example

'use strict';

const http = require('http');
const express = require('express');
const lambdaHttp = require('lambda-http');

let app;
let server;

exports.handler = lambdaHttp.newHandler(function(socketPath, callback) {
  app = express();
  server = http.createServer(app);

  app.get('/foo', function(req, res) {
    res.setHeader('Content-Type', 'application/json');
    res.send(JSON.stringify({ message: 'hello bar'}));
  });

  server.on('listening', function() {
    console.log('server listening on socket: ' + socketPath);

    callback(null);
  });

  server.on('error', callback);

  server.listen(socketPath);
});

hapi Example

'use strict';

const Hapi = require('hapi');
const lambdaHttp = require('lambda-http');

let server;

exports.handler = lambdaHttp.newHandler(function(socketPath, callback) {
  server = new Hapi.Server();

  server.connection({ port: socketPath });

  server.route([
    { method: 'GET', path: '/foo', config : { auth: false, handler : function(request, reply){ return reply({ message: 'hello bar'}); } } },
  ]);

  server.start(function(error) {
    if (!error) {
      console.log('server listening on socket: ' + server.info.uri);
    }

    callback(error)
  });
});

About

Use Express, hapi, or other NodeJS web frameworks on API Gateway and Lambda

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published