mercredi 1 juillet 2015

AWS Lambda w/ Node.js Dependencies

I'm having quite a bit of trouble getting my Node.js Lambda script to work. I've narrowed it down to the fact that the script requires two Nodes.js modules (request and mongojs).

var request = require('request'),
mongojs = require('mongojs'),
db = mongojs('CONNECTION_STRING_HERE', ['events']);

exports.handler = function(event, context) {

    var data = event.Records[0].kinesis.data,
        body = new Buffer(data, 'base64').toString('utf-8');

    db.events.insert({
        event_id: '00030050-0000-1000-8000-30f9ed09e058',
        type: {
        primary: 'CameraDiscovery',
        secondary: 'Probe'
    },
    source: {
        source_id: '40:16:7e:68:8b:5c',
        type: 'ENVR'
    },
    payload: body,
       created_at: new Date(),
       last_modified: new Date()
    }, function(err, doc) {

    if (err) return context.fail(err);

    context.succeed('Processed Event');

});

};

How does one ensure that dependencies are compiled so that the code can execute?




Aucun commentaire:

Enregistrer un commentaire