Create your first Golang Lambda With Serverless Framework

- 5 mins

Golang Lambda With Serverless Framework

This article explains step-by-step how to implement a simple AWS Lambda with Serverless Framework.

Prerequisites to follow this article

Why use a AWS lambda?

AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS). It allows you to run your code in response to events without needing to provision or manage servers. With AWS Lambda, you can focus solely on writing your application code while AWS takes care of the infrastructure and scaling for you.



Why use a AWS Serverless Framework?

The Serverless Framework is a tool written in Node that simplifies the deployment and management of serverless applications and functions. It abstracts away many of the complexities involved in setting up and configuring serverless services like AWS Lambda, API Gateway, and others.

Get Started

Step 1: Install Serverless Framework

Open your terminal and run the following command to install the Serverless Framework globally:

npm install -g serverless

NOTE : If you type serverless in the terminal you can choose a template to generate a skeleton of the project.

Serlverless CLI Serverless crete skeleton project

Step 2: Create simple Health Checks in Go

Create a directory from the project and initialize a Golang project.

NOTE : Feel free to change the name of the project.

mkdir GoServerless

cd GoServerless

go mod init go-lambda-serverless

Finally, create your main.go with a simple health check.

package main

import (

type Response events.APIGatewayProxyResponse

func Handler(ctx context.Context, request events.LambdaFunctionURLRequest) (Response, error) {
 return Response{Body: "It works!", StatusCode: 200}, nil

func main() {

Then install all dependencies

go mod tidy

Step 3: Compile de project

env GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o bin/health main.go

Step 4: Create a Serverless config file

Create serverless.yml on the root project with the content:

service: go-serverless # Define your service name

  name: aws
  runtime: go1.x
  region: eu-central-1 # Put your AWS region

    - '!./**'
    - ./bin/**

    handler: bin/health # route to binary
      - http:
          path: /health
          method: get
          cors: true
          private: false

NOTE : You can find the all information on the oficial documentation:

Step 5: Deploy!

Thanks to the Serverless framework it is very easy to deploy any application, just serverless deploy on the console and the magic happens :-)

serverless deploy

NOTE : If you get more information about the deploy you can add --verbose parameter.

Serverless deploy Serverless deploy output

And thats all! the framework takes the responsibility to create the necessary infrastructure on AWS and return the URL to the defined endpoint.

You can try the endpoint by CURL

curl -X GET

Or if you prefer you can try via Postman

Postman Try the endpoint by postman

You can also use the same Serverless Framework

serverless invoke -f health

Serverless health Try the service by Serverless Framework


You can remove all the application including the infrastructure by de Serverless Framework.

serverless remove

Serverless remove


In this article we have been able to see step by step how to create a very simple application with GO and deploy it using Serverless Framework, a great tool that makes our life much easier.

I did not pretend to make a very detailed article, I just wanted to show how to make a simple application from zero.

You can read the article on Medium

Albert Colom

Albert Colom

Backend developer