Writing a Lambda function in Go
Follow the steps in this section to create your first Lambda function in Go from scratch:
- To write a Lambda function, we need to install some dependencies. Hence, open a new terminal session, and install the Go Lambda package using the following command:
go get github.com/aws/aws-lambda-go/lambda
- Next, open your favorite Go IDE or editor; in my case, I will work with VS Code. Create a new project directory in your GOPATH and then paste the following content into a
main.go
file:
package main import"github.com/aws/aws-lambda-go/lambda" funchandler() (string, error){ return"Welcome to Serverless world", nil } funcmain() { lambda.Start(handler) }
The previous code uses the lambda.Start()
method to register an entry-point handler that contains the code that will be executed when a Lambda function is invoked. Each language supported by Lambda has its own requirements for how a function handler can be defined. For Golang, the handler signature must meet the following...