Invoke from local lambda?

Can you invoke lambda functions that are only in your computer locally?

I want to use the aws sam cli to invoke one function who invokes another one synchronously, being both only in my local computer.

I’ve been looking at enviorment variables and stuff but I dont find anything related to this.

Im writting the lambdas in python 3.9

You can use cloud formation for this. If you’re using vs code or jetbrains you can install the Sam extension. These extensions can create a template for you. Once the template is created you can invoke a lambda locally. You can probably find a tutorial by searching cloudformation vscode

I do have the extension, I am able to invoke one lambda locally, what I want is invoke another local lambda from the python code of the first one

Also tsm for your answer :3

I’ve done most of this with AWS SAM, which creates virtual api gateway and lets you run locally- except the synchronous invocation part, I’m not sure that works since that’s done via SDK and an ARN or function name. Worth a try.

I would make sure you’re not going down a rabbit hole though, invoking one lambda from another is widely considered an anti-pattern, especially synchronously. Usually you’d want to use SNS, or a queue, or step functions, or the api url for things like this.

I’ve done that locally too, both with https://localstack.cloud and using custom code for testing that mocks all the integrations between functions.

Ohh, I’ll check if those alternatives fit my needs.

Thank you for taking your time on this, I didn’t know it was considered anti-pattern, I just saw it was technically possible on the sam documentation and wanted to try it out.

Yeah, sometimes it’s warranted, but you pay for both lambdas while the first waits for the second. It can also be hard to debug. Good luck!

Hi
Could I request you to explain ur local setup for a noob ? I’m just starting on the AWS lambda rabbit hole and am unsure on how to setup a local dev stack.

Seems u have rolled ur own (I don’t know what localstack is) ? Any recommendations though ?

Good starting place are the aws SAM docs- look at examples for an api and using sam local. The tooling for intellij works with this too- you can invoke local instances of lambdas, or front them with a Sam provided virtual api gateway and do rest requests. I can give you more details later, gotta drive home, but the Sam docs are a good start!

Python has a module: https://pypi.org/project/python-lambda-local/

You can define the event data and env cars, as well as other settings. I have used this for local testing and works pretty well.

Edit: just realized you are trying to invoke one lambda from another. You might be able to accomplish that with this, with some modifications to run probably run a subprocess with the command.

You can do this with localstack as well. But you have to treat it like it’s actually deployed on AWS: package your code, run update-function via the cli or equivalent, etc. I haven’t found a way to debug something like that, but it is helpful if you need to run a whole chain of stuff locally