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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745665733a4639112.html
评论列表(0条)