Deploy Hapi.js API's on Amazon Lambda
Switch branches/tags
Nothing to show
Clone or download

README.md

hapi-lambda

npm version

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

Not compatible with Hapi 17+

Please ensure your package.json file references

"hapi": "^16.6.3"

or this module will crash.

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.