0.0.4 • Published 9 years ago

hapi-aws-lambda v0.0.4

Weekly downloads
1
License
BSD-3-Clause
Repository
github
Last release
9 years ago

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);
        });
    }
});
0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

10 years ago