Home
Blog
How-to-create-a-serverless-function-in-netlify
Oct 15, 2023

How to Create a Serverless Function in Netlify

#serverless
#netlify

Prerequisites

  1. Install go lang
  2. Install the netlify cli
npm install netlify-cli -g

Creating the serverless function

  1. 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"

  1. Install the go dependencies
cd netlify/functions/hello
go mod tidy
  1. Commit and push the changes, Netlify will pick up the go lambda when your site is being built.

Testing locally

  1. In your projects root directory run netlify dev
  2. Navigate to the lambda url http://localhost:8888/.netlify/functions/hello

You should get a 200 response with message saying "Hello, World!"

https://docs.netlify.com/functions/get-started/?fn-language=go

Built and designed by Chad Adams

Copyright © 2024 Chad Adams