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)
You just need to install the
netlify-cli
npm package and then executenetlify 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.
Yogesh, Started using the CLI today, and LOVE it. Thanks so much for the tip!
That's awesomeπ
Yogesh, Thank you! Greatly appreciate it.
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
Fraser!!! LOVE the Netlify CLI. INCREDIBLE. thank you so much.
Thank you! So helpful.
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...
Thanks! I will check that out.
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...
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.