hapi-aws-lambda

0.0.4 • Public • Published

hapi-aws-lambda

Call AWS lambda functions from your hapi apps! And get all the goodness of server methods, including free caching.

Installation

const Hapi = require('hapi');
 
const server = new Hapi.Server();
server.connection({ port: 4000 });
 
server.register({
    register: require('hapi-aws-lambda'),
    options: {
        config: {
            region: 'us-east-1',
            credentials: {
                accessKeyId: 'XXX',
                secretAccessKey: 'XXX'
            }
        }
    }
}, (err) => {
 
    if (err) {
        throw err;
    }
 
    // Use it here!
 
    server.start(() => {
        console.log('Server started!');
    });
});

Usage

The lamda handler

server.route({
    method: 'GET',
    path: '/',
    handler: {
        lambda: {
            func: 'myExampleFunction', // short name or full arn
            payload: { name: 'matt' }
        }
    }
});

The lamda server method (free caching for your lambdas!)

server.lambda('myExampleFunction', {
    cache: {
        expiresIn: 10000
    }
});
 
server.route({
    method: 'GET',
    path: '/',
    handler: function (request, reply) {
 
        server.methods.myExampleFunction({ name: 'matt' }, (err, data) => {
 
            if (err) {
                throw err;
            }
 
            reply(data);
        });
    }
});

Dependents (0)

Package Sidebar

Install

npm i hapi-aws-lambda

Weekly Downloads

3

Version

0.0.4

License

BSD-3-Clause

Last publish

Collaborators

  • mtharrison