AWS API Gateway映射模板JSON [英] AWS API Gateway Mapping Template JSON
问题描述
我有一个使用"Lambda代理集成" 不的API阶段,该阶段具有传递错误的Lambda函数.
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"
}
无论我尝试了什么,body总是以空字符串,空正文或无效JSON的形式返回.
Whatever I have tried, body always returns as a blank string, an empty body, or an invalid JSON.
这是我所拥有的最接近的,但是它返回无效的JSON: $ util.parseJson($ input.path("$.errorMessage")).body
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}
有可能做我想做的事吗?我找不到$ util.parseJson(即stringify)的反向字符.
Is it possible to do what I'm after? I can't find a reverse for $util.parseJson (i.e, stringify).
谢谢!
推荐答案
我认为原始海报可能在过去11个月中一直在发展,但是如果其他任何人偶然发现此问题,请 $ input.json('$ .errorMessage.body')
应该可以.
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.
这篇关于AWS API Gateway映射模板JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!