It is quite simple to deploy the go function on the AWS Lambda using Aws Lambda Go. I'll demonstrate the lambda function using a simple request as input for lambda and return Ok response for this example.
-
Get the aws lambda tool using.
go get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
-
Create your lambda function.
// main.go package main import ( "fmt" "github.com/aws/aws-lambda-go/lambda" ) type Request struct { ID float64 `json:"id"` Value string `json:"value"` } type Response struct { Message string `json:"message"` Ok bool `json:"ok"` } func Handler(request Request) (Response, error) { return Response{ Message: fmt.Sprintf("Process Request ID %f", request.ID), Ok: true, }, nil } func main() { // Make the handler available for Remote Procedure Call by AWS Lambda lambda.Start(Handler) }
-
Build your lambda function for linux
GOOS=linux go build -o main
-
Set required permission for execution
sudo chmod +x main
-
Zip the build
zip -9 main.zip main
-
Upload to lambda and test using the following event argument.
{ "id": 123, "value": "This is a test value" }
It gives us the following response.
{ "message": "Process Request ID 123.000000", "ok": true }
- What is AWS Lambda
- Working with AWS Lambda Functions
- AWS Lambda Programming Model
- AWS Lambda Applications
- AWS Lambda Go Repository
TLDR; The link to my medium article.