AWS API Gateway Mapping Template JSON

自闭症网瘾萝莉.ら 提交于 2021-01-07 02:28:29

问题


I've got a API stage that's NOT using "Lambda Proxy integration" which has a Lambda function passing an error.

In the mapping template I have this:

$input.path("$.errorMessage")

Which results in the output of this:

{
    "headers": {
        "apiVersion": "20190218.1",
        "isTesting": true
    },
    "body": {
        "statusCode": 503,
        "status": "Service Unavailable",
        "title": "One or more of our data providers are currently offline for scheduled maintenance"
     }
}

The header values are mapped to template headers and pull through correctly, however I need the body to transform to this:

{
   "statusCode": 503,
   "status": "Service Unavailable",
   "title": "One or more of our data providers are currently offline for scheduled maintenance"
}

Whatever I have tried, body always returns as a blank string, an empty body, or an invalid JSON.

This is the closest I've got but it returns an invalid JSON:
$util.parseJson($input.path("$.errorMessage")).body

Result (comes back with no quotes):

{statusCode=503, status=Service Unavailable, title=One or more of our data providers are currently offline for scheduled maintenance}

Is it possible to do what I'm after? I can't find a reverse for $util.parseJson (i.e, stringify).

Thanks!


回答1:


I think the original poster has probably moved on in the past 11 months, but in case anyone else stumbles across this question, $input.json('$.errorMessage.body') should work.



来源:https://stackoverflow.com/questions/54741560/aws-api-gateway-mapping-template-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!