marconi1992 / serverless-offline-lambda

Emulate AWS λ Invocations locally when developing your Serverless project
https://www.npmjs.com/package/serverless-offline-lambda
MIT License
10 stars 10 forks source link

404 Error When Invoking Lambdas Locally #13

Open xiaoqiaomm opened 5 years ago

xiaoqiaomm commented 5 years ago

I would like to use this plugin to invoke a lambda from within another lambda. Below is my lambda function which will invoke another lambda locally and when I run "serverless invoke local --function local-lambda" it throws a 404 exception. Does it mean the function it's invoking is not deployed into localhost:4000?

export async function localLambda(event) { const lambda = new AWS.Lambda({ region: 'us-east-1', endpoint: 'http://localhost:4000', }); let response; const lambdaInvokeParameters = { FunctionName: 'my-function-local', InvocationType: 'Event', LogType: 'Tail', Payload: JSON.stringify({ "body": {"tableName":"my_table"} }), } try { response = await lambda.invoke(lambdaInvokeParameters).promise(); } catch (err) { return (err); } console.log("response: ", response); }

sergueyarellano commented 5 years ago

Yeah, the same was happening to me.

I was passing: FunctionName: myservice-mystage-myfunction

The plugin is expecting just the name of the function: FunctionName: myfunction

Anyway, you can check it in the code, put some logs around this part:

          const funOptions = funOptionsCache[functionName];

          if (!funOptions) {
            return reply().code(404);
          }

          const handler = functionHelper.createHandler(funOptions, this.options);

          if (!handler) {
            return reply().code(404);
          }
          const { payload } = req;

Hope it helps

marconi1992 commented 5 years ago

Thanks for the feedback @sergueyarellano, I'll take a look on it today.

marconi1992 commented 5 years ago

Duplicate of #8