October 15, 2023
How to Create a Serverless Function in Netlify
#serverless
#netlify
Prerequisites
- Install go lang
- Install the netlify cli
npm install netlify-cli -g
Creating the serverless function
- Create a go serverless function using the netlify cli
netlify functions:create hello -l go
1a. Pick option "Serverless function (Node/Go)" 1b. Pick option "hello-world Basic function that shows how to create a handler and return a response"
- Install the go dependencies
cd netlify/functions/hello
go mod tidy
- Commit and push the changes, Netlify will pick up the go lambda when your site is being built.
Testing locally
- In your projects root directory run netlify dev
- Navigate to the lambda url http://localhost:8888/.netlify/functions/hello
You should get a 200 response with message saying "Hello, World!"
Links
https://docs.netlify.com/functions/get-started/?fn-language=go