Libraries, samples, and tools to help Go developers develop AWS Lambda functions.
To learn more about writing AWS Lambda functions in Go, go to the official documentation
// main.go
package main
import (
"github.com/aws/aws-lambda-go/lambda"
)
func hello() (string, error) {
return "Hello λ!", nil
}
func main() {
// Make the handler available for Remote Procedure Call by AWS Lambda
lambda.Start(hello)
}
Preparing a binary to deploy to AWS Lambda requires that it is compiled for Linux and placed into a .zip file.
# Remember to build your handler executable for Linux!
GOOS=linux GOARCH=amd64 go build -o main main.go
zip main.zip main
Windows developers may have trouble producing a zip file that marks the binary as executable on Linux. To create a .zip that will work on AWS Lambda, the build-lambda-zip
the tool may be helpful.
Get the tool
set GO111MODULE=on
go.exe get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
Use the tool from your GOPATH
. If you have a default installation of Go, the tool will be in %USERPROFILE%\Go\bin
.
in cmd.exe:
set GOOS=linux
set GOARCH=amd64
set CGO_ENABLED=0
go build -o main main.go
%USERPROFILE%\Go\bin\build-lambda-zip.exe -o main.zip main
in Powershell: