AWS API Gateway Header and Body Mappings in Integration Response

前端 未结 1 1498
你的背包
你的背包 2020-12-22 08:04

I am trying to properly setup Body Mapping and Header Mapping in the Integration Response for an API Gateway endpoint.

In our Lambda we have

if (res         


        
1条回答
  •  太阳男子
    2020-12-22 08:30

    Did you try to use Lambda Error Regex in Integration Response? For example:

    .*"status":400.*

    body mapping templetes:

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

    I created an error function in my Lamda:

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

    usage:

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

    0 讨论(0)
提交回复
热议问题