Why Go is the New King of Serverless (Period)?
\n\nWhen it comes to serverless architecture, most developers think of JavaScript (Node.js) or Python. It's logical: they are simple, popular, and tons of tutorials are written for them. But there is one problem: cold start.
\n\nImagine: you run a Lambda function in Python. The first request after idle time takes 3-5 seconds. The user waits. The business loses money. Now imagine the same function in Go: 100-200 milliseconds. Feel the difference?
\n\nGo (Golang) is a language created within Google to solve problems where performance and simplicity matter. In the serverless world, it offers three key advantages:
\n- \n
- Instant cold start — a compiled binary starts in milliseconds. \n
- Low memory consumption — you pay less and get more. \n
- Single binary — no dependencies, just upload and forget. \n
In this article, we'll break down how to write serverless functions in Go for AWS Lambda, look at real code examples, and compare with alternatives. If you're tired of waiting for a Python function to "warm up" — welcome.
\n\nHow to Set Up AWS Lambda on Go: Step-by-Step Guide
\n\nBefore writing code, let's figure out the tooling. To work with Go on AWS Lambda, you will need:
\n- \n
- Go installed (version 1.21+). \n
- The
aws-cliutility (or the AWS console). \n - A basic understanding of what a Handler is. \n
Step 1. Create a project
\nCreate a new directory and initialize the module:
\nmkdir go-lambda-example\ncd go-lambda-example\ngo mod init example.com/lambda\n\nStep 2. Write your first function
\nCreate a file main.go. Here is a minimal example of a serverless function in Go that processes JSON and returns a response:
package main\n\nimport (\n "context"\n "fmt"\n\n "github.com/aws/aws-lambda-go/lambda"\n)\n\n// MyEvent — incoming event structure\ntype MyEvent struct {\n Name string `json:"name"`\n}\n\n// MyResponse — response structure\ntype MyResponse struct {\n Message string `json:"message"`\n Status int `json:"status"`\n}\n\n// HandleRequest — main Lambda handler\nfunc HandleRequest(ctx context.Context, event MyEvent) (MyResponse, error) {\n if event.Name == "" {\n return MyResponse{Message: "Hello, anonymous!", Status: 200}, nil\n }\n return MyResponse{\n Message: fmt.Sprintf("Hello, %s! Welcome to serverless with Go.", event.Name),\n Status: 200,\n }, nil\n}\n\nfunc main() {\n lambda.Start(HandleRequest)\n}\n\nImportant: The function must accept context.Context and return (T, error). This is the standard for Go Lambda.
Step 3. Compile for Linux
\nAWS Lambda runs on Linux, so the binary must be built for that OS:
\nGOOS=linux GOARCH=amd64 go build -o bootstrap main.go\nNote: the output file must be named bootstrap — this is an AWS Lambda requirement for Go.
Step 4. Package and upload
\nPackage the binary into a ZIP:
\nzip function.zip bootstrap\nNow upload it to AWS Lambda via the console or CLI. Done! Your first serverless function in Go is running.
\n\nAdvanced Example: Working with S3 and DynamoDB
\nNow that the basics are covered, let's write something useful. Suppose we need to process file uploads to S3 and save metadata to DynamoDB. This is a classic serverless scenario.
\n\nInstall the necessary SDKs:
\ngo get github.com/aws/aws-lambda-go/events\ngo get github.com/aws/aws-sdk-go-v2/service/s3\ngo get github.com/aws/aws-sdk-go-v2/service/dynamodb\n\