I have been trying to get my first lambda function in Go running via the Amazon API Gateway.
I have the following package set up in go. The goal is to send a JSON request and log and return the body of that request:
package main
import (
"net/http"
"log"
"github.com/aws/aws-lambda-go/lambda"
"github.com/aws/aws-lambda-go/events"
)
func Handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
//These log statements return empty regardless of JSON input.
log.Print(request.body)
return events.APIGatewayProxyResponse{
StatusCode: http.StatusOK,
Body: request.Body
}, nil
}
func main() {
lambda.Start(Handler)
}
I can build and zip this and upload it to the AWS lambda manager. The AWS lambda manager contains an option to use a test event which I can configure with a JSON string
{
"testint": 1,
"teststring": "test"
}
However, if I run this test, I get the following result:
{
"statusCode": 200,
"headers": null,
"body": ""
}
I would expect the body to actually contain the json I passed to the function, but clearly something is going wrong.