简体   繁体   English

AWS API 网关映射模板 JSON

[英]AWS API Gateway Mapping Template JSON

I've got a API stage that's NOT using "Lambda Proxy integration" which has a Lambda function passing an error.我有一个使用“Lambda 代理集成”的 API 阶段,它有一个传递错误的 Lambda 函数。

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.无论我尝试过什么,body 总是以空白字符串、空正文或无效 JSON 的形式返回。

This is the closest I've got but it returns an invalid JSON:这是我得到的最接近的,但它返回一个无效的 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 (ie, stringify).我找不到 $util.parseJson 的反向(即 stringify)。

Thanks!谢谢!

我认为最初的海报在过去 11 个月内可能已经发生了变化,但如果其他人偶然发现这个问题, $input.json('$.errorMessage.body')应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM