admin管理员组文章数量:1026989
I have been integrating express step functions to API Gateway endpoints and have run into an issue where I am returning following object
{
"statusCode":"500",
"body":{
"message: "Internal Server Error"
}
}
OR
{
"statusCode": "200",
"body": {
"result": {...}
}
}
I want to be able to map the statusCode to HTTP status and the body to HTTP response body. I have been able to map the statusCode to the HTTP status as follows,
##velocity template
#set($inputRoot=$input.path('$'))
#set($output=$util.parseJson($inputRoot.output))
#set($context.responseOverride.status=$output.statusCode)
this works but when I try to return the body, what I get in response (in Postman) is:
{message=Internal Server Error
}
I have been integrating express step functions to API Gateway endpoints and have run into an issue where I am returning following object
{
"statusCode":"500",
"body":{
"message: "Internal Server Error"
}
}
OR
{
"statusCode": "200",
"body": {
"result": {...}
}
}
I want to be able to map the statusCode to HTTP status and the body to HTTP response body. I have been able to map the statusCode to the HTTP status as follows,
##velocity template
#set($inputRoot=$input.path('$'))
#set($output=$util.parseJson($inputRoot.output))
#set($context.responseOverride.status=$output.statusCode)
this works but when I try to return the body, what I get in response (in Postman) is:
{message=Internal Server Error
}
Share
Improve this question
edited Nov 16, 2024 at 9:35
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Nov 16, 2024 at 4:16
PratikPratik
3072 silver badges9 bronze badges
4
- What specific body output are you aiming to achieve? Based on the description, it seems the body already meets your requirements. – Gerard Haw Commented Nov 16, 2024 at 4:24
- I want it in Json format. { "message": "Internal Server Error" }, as of now I am getting message=..., – Pratik Commented Nov 16, 2024 at 21:21
- Basically I want to map Body as is to Http Response Body – Pratik Commented Nov 16, 2024 at 21:23
- Can you provide some API Gateway logs? – fa44 Commented Nov 19, 2024 at 21:33
1 Answer
Reset to default 0The issue is that you have parsed the json in the template, what you want is:
##velocity template
#set($output=$input.json('$.output'))
#set($context.responseOverride.status=$input.path('$.output.statusCode')
https://docs.aws.amazon/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#input-variable-reference
The .json function of the input object will convert it to a json string istead of an object internally in VTL
I have been integrating express step functions to API Gateway endpoints and have run into an issue where I am returning following object
{
"statusCode":"500",
"body":{
"message: "Internal Server Error"
}
}
OR
{
"statusCode": "200",
"body": {
"result": {...}
}
}
I want to be able to map the statusCode to HTTP status and the body to HTTP response body. I have been able to map the statusCode to the HTTP status as follows,
##velocity template
#set($inputRoot=$input.path('$'))
#set($output=$util.parseJson($inputRoot.output))
#set($context.responseOverride.status=$output.statusCode)
this works but when I try to return the body, what I get in response (in Postman) is:
{message=Internal Server Error
}
I have been integrating express step functions to API Gateway endpoints and have run into an issue where I am returning following object
{
"statusCode":"500",
"body":{
"message: "Internal Server Error"
}
}
OR
{
"statusCode": "200",
"body": {
"result": {...}
}
}
I want to be able to map the statusCode to HTTP status and the body to HTTP response body. I have been able to map the statusCode to the HTTP status as follows,
##velocity template
#set($inputRoot=$input.path('$'))
#set($output=$util.parseJson($inputRoot.output))
#set($context.responseOverride.status=$output.statusCode)
this works but when I try to return the body, what I get in response (in Postman) is:
{message=Internal Server Error
}
Share
Improve this question
edited Nov 16, 2024 at 9:35
Brian Tompsett - 汤莱恩
5,89372 gold badges61 silver badges133 bronze badges
asked Nov 16, 2024 at 4:16
PratikPratik
3072 silver badges9 bronze badges
4
- What specific body output are you aiming to achieve? Based on the description, it seems the body already meets your requirements. – Gerard Haw Commented Nov 16, 2024 at 4:24
- I want it in Json format. { "message": "Internal Server Error" }, as of now I am getting message=..., – Pratik Commented Nov 16, 2024 at 21:21
- Basically I want to map Body as is to Http Response Body – Pratik Commented Nov 16, 2024 at 21:23
- Can you provide some API Gateway logs? – fa44 Commented Nov 19, 2024 at 21:33
1 Answer
Reset to default 0The issue is that you have parsed the json in the template, what you want is:
##velocity template
#set($output=$input.json('$.output'))
#set($context.responseOverride.status=$input.path('$.output.statusCode')
https://docs.aws.amazon/apigateway/latest/developerguide/api-gateway-mapping-template-reference.html#input-variable-reference
The .json function of the input object will convert it to a json string istead of an object internally in VTL
版权声明:本文标题:amazon web services - AWS API Gateway integration response template mapping for step functions - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745665732a2162166.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论