Hey,
If you have been scratching your head why does API Gateway returns 502 and within your code there are no exceptions ?
Does your API gateway response contain something like below ?
Then make sure that you are returning correct response object containing body and status code i.e.
var response = { statusCode: 200, body: '\0/' };
If you still see problem then consider if you are returning complex objects in your body ? If so the following should be additionally applied before returning
response.body = JSON.stringify(response.body)
And thats it 🙂 Solved the problem for me