0
votes

I am using the AWS labs' serverless container (https://github.com/awslabs/aws-serverless-java-container) to handle the lambda entrypoint and response for a lambda that returns HTML. It appears that it calls the lambda and returns the HTML just fine from the lambda. However, API Gateway then throws a fit processing the response. I am using the API Gateway as a proxy, not configuring individual endpoints.

Wed Jun 21 20:53:29 UTC 2017 : Endpoint response body before transformations: --- statusCode: 200 headers: Content-Type: "text/html" body: "\r\n\r\nhttp://www.w3.org/1999/xhtml\"\r\n \ \ lang=\"en\">\r\n \r\n \r\n \ \ Page Title\r\n \r\n \r\n \ \ \r\n \r\n\ \ \r\n \r\n ... [TRUNCATED] Wed Jun 21 20:53:29 UTC 2017 : Endpoint response headers: {x-amzn-Remapped-Content-Length=0, x-amzn-RequestId=adb2b101-56c3-11e7-afc6-8383d836980f, Connection=keep-alive, Content-Length=17551, Date=Wed, 21 Jun 2017 20:53:29 GMT, X-Amzn-Trace-Id=root=1-594adcc9-6987c6ed102696c505538b02;sampled=0, Content-Type=application/octet-stream} Wed Jun 21 20:53:29 UTC 2017 : Execution failed due to configuration error: Malformed Lambda proxy response Wed Jun 21 20:53:29 UTC 2017 : Method completed with status: 502

As you can see from the logs, the AWS own Java object, AwsProxyResponse, properly wraps the HTML content how AWS coded it. You see it returning the proper body and text/html headers. It seems API Gateway then blows up handling a response from AWS's own response.

How do I get AWS Gateway to properly handle the response when the response form the lambda is Content-Type: test/html?

1

1 Answers

3
votes

The response from the Lambda function does not look correct. It appears a raw string without any format.

It should be JSON in the format:

{
  "statusCode": num,
  "headers" : {
    "key" : "value"
  },
  "body" : "anything"
}