Netlify function has empty request body

I have a function that will proxy webhook requests from an API to one of our internal services. This function is setup using Golang and expects a APIGatewayProxyRequest. It has been working just fine for months now, but today we started to have issues with it not having a request body (with no changes to the code base). After debugging each of the services I’ve found out that the function itself is not receiving all data from the AWS API gateway. All I see come through now are just the request headers, no request body or anything else. As far as I know AWS isn’t having any issues and Netlify isn’t either so I’m confused on how this could have changed at all.

This is what I’m seeing come through currently for APIGatewayProxyRequest:

{
  "resource": "",
  "path": "FILTERED",
  "httpMethod": "GET",
  "headers": {
    "client-ip": "FILTERED",
    "content-type": "application/json; charset=utf-8",
    "user-agent": "FILTERED"
  },
  "multiValueHeaders": null,
  "queryStringParameters": {},
  "multiValueQueryStringParameters": null,
  "pathParameters": null,
  "stageVariables": null,
  "requestContext": {
    "accountId": "",
    "resourceId": "",
    "stage": "",
    "requestId": "",
    "identity": {
      "cognitoIdentityPoolId": "",
      "accountId": "",
      "cognitoIdentityId": "",
      "caller": "",
      "apiKey": "",
      "apiKeyId": "",
      "accessKey": "",
      "sourceIp": "",
      "cognitoAuthenticationType": "",
      "cognitoAuthenticationProvider": "",
      "userArn": "",
      "userAgent": "",
      "user": ""
    },
    "resourcePath": "",
    "authorizer": null,
    "httpMethod": "",
    "apiId": ""
  },
  "body": "" // body should not be empty
}

We expect the body to at least be there in addition to an HMAC signature header which I removed for security reasons. I have already verified the webhook that’s sending to the function works correctly when being sent to https://webhook.site instead, so that doesn’t seem to be the issue.

This is the basic structure of our code:

var defaultResponse = &events.APIGatewayProxyResponse{StatusCode: 200}

type ProxyRequest struct {
	Headers     map[string]string `json:"headers"`
	Method      string            `json:"method"`
	Body        string            `json:"body"`
	QueryParams map[string]string `json:"queryParams"`
}

func handler(request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
	// verify signature....

	p := ProxyRequest{
		Headers:     request.Headers,
		Method:      request.HTTPMethod,
		Body:        request.Body,
		QueryParams: request.QueryStringParameters,
	}

	b, err := json.Marshal(&p)
	if err != nil {
		log.Printf("failed to marshal event to JSON: %v", err)
		return defaultResponse, nil
	}

	// send the json data to one of our internal services....

	return defaultResponse, nil
}
func main() {
	lambda.Start(func(request events.APIGatewayProxyRequest) (*events.APIGatewayProxyResponse, error) {
		start := time.Now()
		resp, err := handler(request)
		log.Printf("function execution took: %v", time.Since(start))
		return resp, err
	})
}

Our netlify.toml file:

# example netlify.toml
[build]
  command = "make build"
  functions = "functions"
  publish = "."
[build.environment]
  GO_IMPORT_PATH = "FILTERED"
  GO111MODULE = "on"
  ## Uncomment to use this redirect for Single Page Applications like create-react-app.
  ## Not needed for static site generators.
  #[[redirects]]
  #  from = "/*"
  #  to = "/index.html"
  #  status = 200

  ## (optional) Settings for Netlify Dev
  ## https://github.com/netlify/netlify-dev-plugin#project-detection
  #[dev]
  #  command = "yarn start" # Command to start your dev server
  #  port = 3000 # Port that the dev server will be listening on
  #  publish = "dist" # Folder with the static content for _redirect file

  ## more info on configuring this file: https://www.netlify.com/docs/netlify-toml-reference/

Disregard this. The issue was due to the domain change from netlify.com to netlify.app…

1 Like