Aws-sam-cli: Invoking a lamnda from a lambda fails in SAM local

Created on 30 Nov 2017  路  10Comments  路  Source: aws/aws-sam-cli

I have two lambdas runnignin SAM local, one of them (lambda1) is an api endpoint and it works fine. Now, I add another lambda (lambda2) and I want lambda1 to call it, so I add this code in lambda1:

const lambda = new aws.Lambda({ region: 'us-east-1' });
    lambda.invoke({
        FunctionName: 'lambda2',
        InvocationType: 'Event',
        LogType: 'None',
    }, (err, data) => {
        console.log(err); // ERR HAS AN ERROR
        cb(null, { statusCode: 200, body: data });
    });

And Lambda2 is this:

module.exports.handler = (event, context, cb) => {
    cb(null, true);
};

I get an error in the callback:

{"message":"connect ECONNREFUSED 192.168.65.1:8000","code":"NetworkingError","errno":"ECONNREFUSED","syscall":"connect","address":"192.168.65.1","port":8000,"region":"us-east-1","hostname":"docker.for.mac.localhost","retryable":true,"time":"2017-11-30T18:04:24.985Z"}

Any ideas?

Most helpful comment

@sanathkr I don't think is a duplicate, in #12 is talking about invoking the lambda function from the CLI, while here is talking about the invocation from the code itself.
I get the same ECONNREFUSED when trying to make a request to a lambda from a lambda, any ideas?

All 10 comments

Today, I don't believe we support the exact api as Lambda itself. This sucks because of these types of oddities when you want a completely local experience.

Seems to be related to #12

I think this would be awesome to have, might start trying to chop away at that bit if no one else is working on it.

Hi,

I need to call a Lambda from a Lambda too within SAM local (and then use SAM local to create my Lambdas in the console). Has this been implemented yet?

Any progress on this?

I set up a Lambda to Lambda call on my AWS console and the steps I followed are below. This might be useful for setting up a corresponding call in SAM Local (as I would like to use the template file to deploy to AWS too).

  1. The calling and called Lambda had to be in the same region
  2. I had to create an IAM Role and attach the following policies, AWSLambdaExecute, AWSLambdaRole, and AWSLambdaBasicExecuteRole (I haven't verified if this last policy is required - see the Stackoverflow link I followed below). Then I assigned this as the execution role for the calling Lambda.
  3. The invocation type I used was RequestResponse. The example above used Event which didn't work for me.

https://stackoverflow.com/questions/35754766/nodejs-invoke-an-aws-lambda-function-from-within-another-lambda-function

@MarkWilliams76 do both lambdas run in SAM local? The SO link you provided is about invoking a lambda from another lambda in AWS, not locally.

@aleybovich No. The steps I'm talking about are via AWS Console. I posted as it's what I want to replicate locally in SAM local.

Closing this issue as a dupe of #12

@sanathkr I don't think is a duplicate, in #12 is talking about invoking the lambda function from the CLI, while here is talking about the invocation from the code itself.
I get the same ECONNREFUSED when trying to make a request to a lambda from a lambda, any ideas?

Hello, any progress on this?

this might be superseded by #510

Was this page helpful?
0 / 5 - 0 ratings