我有一个 API 阶段NOT使用“Lambda 代理集成”,其中 Lambda 函数传递错误。
在映射模板中我有这个:
$input.path("$.errorMessage")
其结果是:
{
"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"
}
}
标头值映射到模板标头并正确拉出,但是我需要将正文转换为:
{
"statusCode": 503,
"status": "Service Unavailable",
"title": "One or more of our data providers are currently offline for scheduled maintenance"
}
无论我尝试过什么,body 总是以空白字符串、空正文或无效 JSON 的形式返回。
这是我得到的最接近的结果,但它返回无效的 JSON:
$util.parseJson($input.path("$.errorMessage")).body
结果(返回时不带引号):
{statusCode=503, status=Service Unavailable, title=One or more of our data providers are currently offline for scheduled maintenance}
可以做我想做的事吗?我找不到 $util.parseJson 的反向(即 stringify)。
Thanks!