Skip to content

aliraza-dev/aws-lambda-go-demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 72.8%
  • Dockerfile 27.2%