Skip to content

Instantly share code, notes, and snippets.

@harishb2k
Last active June 28, 2021 17:26
Show Gist options
  • Save harishb2k/e0168f1235aff767f34482a6545f0d55 to your computer and use it in GitHub Desktop.
Save harishb2k/e0168f1235aff767f34482a6545f0d55 to your computer and use it in GitHub Desktop.
Write a AWS Lambda in go

Step 1 - Implement

package main

import (
	"context"
	"fmt"
	"github.com/aws/aws-lambda-go/lambda"
)

type MyEvent struct {
	Name string `json:"name"`
}

func HandleRequest(ctx context.Context, name MyEvent) (string, error) {
	return fmt.Sprintf("Hello %s!", name.Name), nil
}

func main() {
	lambda.Start(HandleRequest)
}

Step 2 - build and zip

GOOS=linux go build .
zip main.zip lambda

Step 3 - Deploy

Deploy to AWS lambda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment