Use Express, hapi, or other NodeJS web frameworks on API Gateway and Lambda
Inspired by https://github.com/awslabs/aws-serverless-express
npm install lambda-http'use strict';consthttp=require('http');constexpress=require('express');constlambdaHttp=require('lambda-http');letapp;letserver;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);});'use strict';constHapi=require('hapi');constlambdaHttp=require('lambda-http');letserver;exports.handler=lambdaHttp.newHandler(function(socketPath,callback){server=newHapi.Server();server.connection({port: socketPath});server.route([{method: 'GET',path: '/foo',config : {auth: false,handler : function(request,reply){returnreply({message: 'hello bar'});}}},]);server.start(function(error){if(!error){console.log('server listening on socket: '+server.info.uri);}callback(error)});});