apalumbo / hapi-lambda

Deploy Hapi.js API's on Amazon Lambda

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

hapi-lambda

npm version

This module will allow you to host your Hapi.js application on Amazon Lambda.

Usage

Your application should already be configured as plugins:

// api.js

exports.register = function (server, options, next) {
    const plugins = [];

    server.register(plugins, () => {
        server.route({
            method: 'GET',
            path: '/',
            handler: function(request, reply){ reply('OK'); }
        });
        return next();
    });
};

exports.register.attributes = { pkg: { name: 'api', version: '1.0.0' } };

Your index.js file that you push to Lambda should look like the following:

// index.js

const hapiLambda = require('hapi-lambda');
const api = require('./api');

hapiLambda.configure([api]);
exports.handler = hapiLambda.handler;

Deployment

Deployment is a much larger topic and not covered by this module, however I highly recommend deploying your Lambda application with Serverless.

About

Deploy Hapi.js API's on Amazon Lambda

License:MIT License


Languages

Language:JavaScript 100.0%