0

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.myLambda.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!

Udo Held
  • 12,314
  • 11
  • 67
  • 93
mikey
  • 1,339
  • 5
  • 22
  • 43
  • 1
    From my 2 years experience with AWS Lambda - I assume you'd like to run them locally in order to unit test them. There are several ways of unit testing AWS Lambda's locally. In this post, they describe one that I have been using and I can recommend: https://blog.atomdata.io/serverless-applications-continuous-delivery-with-aws-lambda-and-api-gateway-part-1-unit-tests-e517aa1cd09e – johni Apr 29 '17 at 09:03
  • I am currently in a similar situation... did you ever find a way to do this? Thanks! – aashah7 May 24 '17 at 03:58

2 Answers2

1

So personally I use serverless as my preferred framework for local, there's also a very promising looking project from atlassian called localstack here - I haven't actually tried the second one! Hope this helps.

Mrk Fldig
  • 4,244
  • 5
  • 33
  • 64
0

So I find out that all I need it to do was to export: accessKeyId and secretAccessKey.

Just for testing put it in code just above your invoke call. Then make sure you set them in a secure place.

I was exporting them

export ACCESS_KEY_ID=yourkey

export SECRET_ACCESS_KEY=yoursecretkey

Now I am using docker so I have them in a config file.

Hope this helps

mikey
  • 1,339
  • 5
  • 22
  • 43