aws apigateway lambda始终返回502 [英] aws apigateway lambda always return 502

查看:77
本文介绍了aws apigateway lambda始终返回502的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为我的代理服务器创建了aws apigateway lambda集成.当我向网关发出get请求时,请求已成功通过.lambda函数也可以成功执行,并在statusstream为200的输出流中写入响应.但是apigateway始终返回502.

I have created aws apigateway lambda integration for my proxy server. When i am making get request to the gateway, the request is successfully going through. The lambda function also executes successfully and writes response in outputstream with statusCode as 200. But apigateway always returns 502.

handleRequest()的片段:

Snippet of handleRequest():

 BufferedReader reader = new BufferedReader(new 
        InputStreamReader(inputStream));
        JSONObject event = (JSONObject) parser.parse(reader);
        request = Input.builder().setEvent(event).build();

    Response response = requestManager.handleRequest(request);
    logger.log(String.format("Response [%s]", response.toString()));

    JSONObject responseJson = new JSONObject();
    responseJson.put("statusCode", response.getStatusCode());
    responseJson.put("headers", response.getHeaders());
    JSONObject jsonBody = (JSONObject) parser.parse(response.getBody());
    responseJson.put("body", jsonBody);
    OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
    logger.log("response recieved");
    logger.log(String.format("responseJson [%s]", responseJson));
    writer.write(responseJson.toJSONString());
    writer.close();
    logger.log(String.format("output stream [%s]", outputStream));

我错过了什么吗?

推荐答案

Lambda的502错误通常表明您正在使用Lambda代理方法,但未生成正确的JSON响应.确保您的回复符合适当的格式.

502 errors with Lambda usuaully indicate that you are using the Lambda proxy method and not generating the proper JSON response. Make sure your response adheres to the appropriate format.

如果仍然遇到问题,请共享由Lambda函数生成的示例JSON.

If you are still having problems, please share a sample JSON generated by your Lambda function.

这篇关于aws apigateway lambda始终返回502的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆