2017-07-14 90 views
1

我正在尋找正確的方法來識別和更改lambda超時errorMessage使用api網關或lambda本身。如何更改默認lambda「errorMessage」通過api網關上200

說一個腳本失敗,因爲超時並拉姆達返回以下消息API網關,與狀態200

{ 
    "errorMessage": "RequestId: 6737e0a4-68af-11e7-8ab8-7fb105ccffaacc Process exited before completing request" 
} 

有沒有辦法用lambda來定義呢?還是讓api網關做一個映射更好?如果是的話,你能否提供任何文件作爲例子?

回答

0

如果您通過AWS控制檯使用API​​網關:

1)點擊你的方法>方法響應>點擊添加響應>輸入HTTP狀態代碼。 例如

2)集成響應>點擊添加集成響應> LAMBDA錯誤的Regex * 「狀態」:404 *

3)身體映射模板>添加應用/ JSON>粘貼此之一:

#set ($errorMessageObj = $util.parseJson($input.path('$.errorMessage'))) 
{ 
    "status" : "$errorMessageObj.status", 
    "errorType" : "$errorMessageObj.errorType", 
    "message" : "$errorMessageObj.errorMessage" 
} 

4)在你的的Lamda創建誤差函數

function error(status, errorType, errorMessage, callback){ 
    callback(JSON.stringify({ 
     status: status, 
     errorType: errorType, 
     errorMessage: errorMessage 
    })); 
} 

5),你可以用它

error(404, "Not Found", "Resource is not found", callback);