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