Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call a lambda from another Lambda all locally within Serverless

I am using serveless + aws + node.js.

I have a lambda calling another lambda. I can't get to run the lot locally. I can invoke both lambdas locally with 'serverless invoke local -f ...' BUT
the caller one comes back with:

{"message":"Function not found: arn:aws:lambda:eu-west-1:5701xxxxxxxxxx:function:the-right-function-name"}

as if the caller function invoked the callee on AWS and not locally.

Is there anyway to do stay local and if yes, what may I be missing?

like image 851
Thibault Jamme Avatar asked Mar 07 '26 12:03

Thibault Jamme


1 Answers

You can achieve that with this plugin. There is a feature of AWS SDK for Lambda that allows you to override the API endpoint of Lambda service. Therefore you can set it to localhost.

const AWS = require('aws-sdk');

const endpoint = process.env.SERVERLESS_SIMULATE ?
  process.env.SERVERLESS_SIMULATE_LAMBDA_ENDPOINT :
  undefined

const lambda = new AWS.Lambda({ endpoint })

For more details, refer to the plugin's readme. Also there is a nice article about that.

like image 92
Vladyslav Usenko Avatar answered Mar 09 '26 03:03

Vladyslav Usenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!