These are chat archives for mentum/lambdaws

18th
Mar 2015
Sylvain Perron
@slvnperron
Mar 18 2015 02:23
@lbertenasco The CLI’s fixed in 1.0.14
Raphaël Antonmattei
@rantonmattei
Mar 18 2015 13:36
Thanks, that's great
Raphaël Antonmattei
@rantonmattei
Mar 18 2015 15:42
Hi there
I am working with S3 events
and the way the user function is called does not allow that because you call :
func.apply(this, event.args);
If I change this to
func.apply(this, [event, context]);
this works fine
so, I was about to submit a PR for that
however I ran into another issue with this line
event.args.push(doneCallback);
https://github.com/mentum/lambdaws/blob/master/lib/LambdaHelper.js#L46
because in my case, the args property is not defined
Here is the event object I get back from the invocation
[ { eventVersion: '2.0', eventSource: 'aws:s3', awsRegion: 'us-east-1', eventTime: '2015-03-18T15:40:07.417Z', eventName: 'ObjectCreated:Put', userIdentity: [Object], requestParameters: [Object], responseElements: [Object], s3: [Object] } ] }
So, that line triggers an error
Failure while running task: TypeError: Cannot call method 'push' of undefined at __lambda__ (/var/task/index.js:13:20)
Raphaël Antonmattei
@rantonmattei
Mar 18 2015 15:59
So, it seems there are differences between your examples (calling lambda from a local process) and what I am doing (calling from an S3 events)
In your example, you do need args
var minus = function(a, b, callback) { /*...*/ };
With S3 events you need the entire event obj and the context
var myFunc = function(event, context) { /*...*/ };
So, if I add my change, it's going to break the scenario in your example
Raphaël Antonmattei
@rantonmattei
Mar 18 2015 16:08
so, here is what I suggest:
function __lambda__ (event, context) {
    var utils               = require('./_utils'),
        callbackHandler     = require('./_callbackHandler'),
        externalsHandler    = require('./_externalsHandler');

    var doneCallback = callbackHandler.getCallback(event, context);

    if (event.args) {
        event.args.push(doneCallback);
    }

    var externals = /*externals*/null; // The external libraries to install, injected below
    var func = /*user function*/null; // The user function or module to run, injected below

    var runUserFunction = function() {
        try {
            if (event.args) {
                func.apply(this, event.args);
            } else {
                func.apply(this, [event, context]);
            }
        } catch(error) {
            doneCallback(utils.objectifyError(error));
        }
    };

    try { externalsHandler.installExternals(externals, runUserFunction) }
    catch(error) { doneCallback(utils.objectifyError(error)) }
}
Raphaël Antonmattei
@rantonmattei
Mar 18 2015 16:35
I've a PR out: mentum/lambdaws#63
Sylvain Perron
@slvnperron
Mar 18 2015 17:50
@rantonmattei You are right about the events thing. Thanks a lot for the contribution. I’ll have a look later today!