DEV Community

Christopher Wray
Christopher Wray

Posted on

I need some Lambda Function/ Netlify Function stuff.

What I am trying to do is invoke a function by sending a POST request directly to it then send the data sent in the request to an api.

I know what I need to do, and I think I know how, but testing, quite frankly, is a pain in the butt while in development.

Would love to learn how to test functions locally before having to republish on Netlify/ Amazon each time an update is made.

Any help would be awesome!

Top comments (11)

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

You just need to install the netlify-cli npm package and then execute netlify dev command from your project.

That way you can test lambda functions even on local machine.

Check out this article where I have explained in detail.

You can also directly check the final code on the GitHub repository.

Collapse
 
cwraytech profile image
Christopher Wray

Yogesh, Started using the CLI today, and LOVE it. Thanks so much for the tip!

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

That's awesomeπŸ‘

Collapse
 
cwraytech profile image
Christopher Wray

Yogesh, Thank you! Greatly appreciate it.

Collapse
 
fmctaggart profile image
Fraser McTaggart • Edited

You can test on a local machine using the netlify cli. Specify your dev command in your netlify.toml file. Then type
Netlify dev

This spins up your dev command (eg. Npm run dev), and your function lambdas. You can access them both via localhost:8888
Your functions will be accessed via
Localhost:8888/.netlify/functions

You can use Postman to test.

Netlify Dev

Collapse
 
cwraytech profile image
Christopher Wray

Fraser!!! LOVE the Netlify CLI. INCREDIBLE. thank you so much.

Collapse
 
cwraytech profile image
Christopher Wray

Thank you! So helpful.

Collapse
 
luckybusted profile image
Ivan Ushmorov

You could invoke Lambda functions locally via the serverless framework. The best and easiest way to develop and test serverless applications IMO.
serverless-stack.com/chapters/invo...

Collapse
 
cwraytech profile image
Christopher Wray

Thanks! I will check that out.

Collapse
 
chrisdrit profile image
ChrisDrit

I just started playing around with Lambda, hit the same issues you describe, and have been wanting to explore this...

"This command starts a local endpoint that emulates AWS Lambda."

docs.aws.amazon.com/serverless-app...

Collapse
 
cwraytech profile image
Christopher Wray

Looks like Netlify has a package set up for testing that I missed in my search last night. It is linked from another couple people here in the comments.