I got this code from https://github.com/aws/aws-lambda-go/blob/master/events/README_ApiGatewayEvent.md :
package main import ( "context" "fmt" "log" "github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/lambda" ) func handleRequest(ctx context.Context, request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) { fmt.Printf("Processing request data for request %s.\n", request.RequestContext.RequestID) fmt.Printf("Body size = %d.\n", len(request.Body)) fmt.Println("Headers:") for key, value := range request.Headers { fmt.Printf(" %s: %s\n", key, value) } log.Printf("%v", request.Body) return events.APIGatewayProxyResponse{Body: request.Body, StatusCode: 200}, nil } func main() { lambda.Start(handleRequest) } I only added: the log: log.Printf("%v", request.Body)
When I compile and use the lambda test GUI, I send this:
{"body":"[{\"id\":\"123\"}]"} and the log in the tab shows this:
2021/08/16 08:51:50 [{"id":"123"}] However, when I do this:
curl https://qmk743l1p0.execute-api.us-east-1.amazonaws.com/default/simplegateway -d '{"body":"[{\"id\":\"123\"}]"}' --header "Content-Type: application/json" I get this in the CloudWatch logs:
2021/08/16 08:56:07 {"body":"[{\"id\":\"123\"}]"} I have no idea why request.body would have two different values when going through the http gateway.
How do I get the intended "body" in both the lambda test GUI and in through the http API gateway?