Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Pull request Compare This branch is 1 commit behind WajahatAliAbid:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
main.go

README.md

Deploy Go on AWS Lambda

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.

Steps

  1. Get the aws lambda tool using.

       go get -u github.com/aws/aws-lambda-go/cmd/build-lambda-zip
  2. 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)
    }
  3. Build your lambda function for linux

    GOOS=linux go build -o main
  4. Set required permission for execution

    sudo chmod +x main
  5. Zip the build

    zip -9 main.zip main
  6. 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
    }

Further Reading

TLDR; The link to my medium article.

You can’t perform that action at this time.