Skip to content

Instantly share code, notes, and snippets.

@harshq
Created October 17, 2021 08:05
Show Gist options
  • Save harshq/f8340e0227ad7489c1f75d2be1c1632e to your computer and use it in GitHub Desktop.
Save harshq/f8340e0227ad7489c1f75d2be1c1632e to your computer and use it in GitHub Desktop.
Simple http api lambda handler in Go
package main
import (
"encoding/json"
"fmt"
"github.com/aws/aws-lambda-go/events"
runtime "github.com/aws/aws-lambda-go/lambda"
)
type Resp struct {
Body string
}
func handleRequest(event events.APIGatewayV2HTTPRequest) (events.APIGatewayProxyResponse, error) {
resp := Resp{
Body: fmt.Sprintf("%s request to %v is successful!", event.RequestContext.HTTP.Method, event.RequestContext.RouteKey),
}
msg, _ := json.Marshal(resp)
return events.APIGatewayProxyResponse{
StatusCode: 200,
Body: string(msg),
}, nil
}
func main() {
runtime.Start(handleRequest)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment