Explain to me please what is the best way to locally test the lambda function. I used sam local and this solution https://github.com/lambci/docker-lambda
for testin
This is how I test local lambda functions without Serverless frameworks, I run an HTTP post on local (quite easy setup for Go)
func HandleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
_, _ = pretty.Println("parsed:", request.Body)
return events.APIGatewayProxyResponse{Body: "response is working", StatusCode: 200}, nil
}
func main() {
environment := loadEnv()
if environment == "develop" {
router.NewRouter()
select {}
} else {
lambda.Start(lambdahandler.HandleRequest)
}
}
func MapToApiGateway(w http.ResponseWriter, r *http.Request) (interface{}, error) {
request := new(EmailResponderRequest)
if err := json.NewDecoder(r.Body).Decode(request); err != nil {
return err.Error(), err
}
apiGatewayRequest := mapHttpRequestToGatewayRequest(*request)
events, err := lambdahandler.HandleRequest(nil, apiGatewayRequest)
if err != nil {
return err.Error(), err
}
return events, nil
}