Created
October 17, 2021 08:05
-
-
Save harshq/f8340e0227ad7489c1f75d2be1c1632e to your computer and use it in GitHub Desktop.
Simple http api lambda handler in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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