Thursday, 27 April 2017

Test Lambda Locally (Lambda function calling another lambda function)

I am learning node and serverless architecture. To test my lambda function locally I am currently using lambda-local which has been working fine so far.

Now I have a function that invoke another lambda function, something like this:

    let lambda = new integration.lambda4m.AWS.Lambda();
    let params = {
        FunctionName: 'my-other-function',
        InvocationType: 'RequestResponse',
        LogType: 'None',
        Payload: JSON.stringify(myEvent)
    };

    return new Promise((resolve, reject) => {

        lambda.invoke(params, function (error, data) {
            if (error) {
                console.log('error on invoke', error);
                reject({
                    statusCode: HttpStatus.INTERNAL_SERVER_ERROR,
                    message: error
                });

            } else {
                console.log('invoke success', data);
                resolve(JSON.parse(data.Payload));
            }
        });

    });

This bit of code does not work locally, but once deployed on aws it's working fine. However deploying to aws it takes about 2 mins. So I was wondering if there is a way to have this code run locally.

Any suggestions?

Thank you!



via mikey

No comments:

Post a Comment