0

我正在使用AWS实验室的无服务器容器(https://github.com/awslabs/aws-serverless-java-container)来处理返回HTML的lambda的入口点和响应。它似乎调用lambda并从lambda返回HTML很好。但是,API网关随后会处理响应。我使用API​​网关作为代理,而不是配置单个端点。AWS API网关返回HTML

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

你可以从日志中看到,AWS自己的Java对象,AwsProxyResponse,妥善包装了HTML内容AWS如何编码它。你会看到它返回正确的body和text/html标题。看起来,API Gateway随即开始处理来自AWS自身响应的响应。

如何让AWS Gateway正确处理响应,当响应形式为lambda时是Content-Type:test/html?

回答

3

来自Lambda函数的响应看起来不正确。它显示为没有任何格式的原始字符串。

它应该是JSON格式:

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

我已经转换的ObjectMapper是读取YAML文件,然后搞砸响应的序列化。然后,这没有按照AWS的预期返回JSON格式的lambda。修复ObjectMapper后,它工作。谢谢! – FiguringThisOut