Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/349.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java AWS lambda:格式错误的lambda代理响应_Java_Amazon Web Services_Aws Lambda_Aws Api Gateway - Fatal编程技术网

Java AWS lambda:格式错误的lambda代理响应

Java AWS lambda:格式错误的lambda代理响应,java,amazon-web-services,aws-lambda,aws-api-gateway,Java,Amazon Web Services,Aws Lambda,Aws Api Gateway,当Lambda坐在API网关后面时,这是一个典型的问题。我在谷歌上搜索了几乎所有的帖子,但仍然不知道为什么失败 我已经阅读了关于响应应该是什么样子的说明 它正在寻找 { "isBase64Encoded": true|false, "statusCode": httpStatusCode, "headers": { "headerName": "headerValue", ... }, "multiValueHeaders": { "headerName": ["

当Lambda坐在API网关后面时,这是一个典型的问题。我在谷歌上搜索了几乎所有的帖子,但仍然不知道为什么失败

我已经阅读了关于响应应该是什么样子的说明
它正在寻找

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "multiValueHeaders": { "headerName": ["headerValue", "headerValue2", ...], ... },
    "body": "..."
}
这是API网关控制台中的测试日志(我已仔细检查,确保字段名称完全相同

有人能帮忙吗

编辑 我已经从响应中删除了“body”,但仍然得到相同的错误。以下是实际日志

Thu Mar 19 23:29:54 UTC 2020 : Received response. Status: 200, Integration latency: 24 ms
Thu Mar 19 23:29:54 UTC 2020 : Endpoint response headers: {Date=Thu, 19 Mar 2020 23:29:54 GMT, Content-Type=application/json, Content-Length=48, Connection=keep-alive, x-amzn-RequestId=f2c2c752-a5e0-45e4-9ff0-d91826b51c7b, x-amzn-Remapped-Content-Length=0, X-Amz-Executed-Version=$LATEST, X-Amzn-Trace-Id=root=1-5e740072-46cee9045a56e04b8023816d;sampled=0}
Thu Mar 19 23:29:54 UTC 2020 : Endpoint response body before transformations: "{\"statusCode\":200,\"isBase64Encoded\":false}"
Thu Mar 19 23:29:54 UTC 2020 : Execution failed due to configuration error: Malformed Lambda proxy response
Thu Mar 19 23:29:54 UTC 2020 : Method completed with status: 502
java应用程序和lambda中的实际JSON响应

{"statusCode":200,"isBase64Encoded":false}

在与Node.js示例进行比较之后,似乎这与处理程序有关

使用请求处理程序时,响应是字符串

public class MyLambda implements RequestHandler<Object, String> {
    @Override
    public String handleRequest(Object input, Context context) {
将其更改为RequestStreamHandler,错误消失

public class APIgatewayTest implements RequestStreamHandler {
    @Override
    public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
从API网关,响应如下

Thu Apr 09 09:13:08 UTC 2020 : Endpoint response body before transformations: {"statusCode":200,"body":"\"Hello from Lambda!\""}
Thu Apr 09 09:13:08 UTC 2020 : Method response body after transformations: "Hello from Lambda!"

生成此响应的代码是什么?@Marcin,它是一个java类。我假设它没有影响,因为API网关与Lambda对话,试图解析Lambda的HTTP响应?这里的结果格式是什么?尝试从您的响应中删除body,以缩小它与结果的关系,并对其进行测试。@SurajBhatia,我在做一个简单的测试,我显示的日志是实际的日志,这意味着body的内容是一个字符串“RESULT”,您的实际JSON响应是什么样子的?
public class APIgatewayTest implements RequestStreamHandler {
    @Override
    public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
Thu Apr 09 09:13:08 UTC 2020 : Endpoint response body before transformations: {"statusCode":200,"body":"\"Hello from Lambda!\""}
Thu Apr 09 09:13:08 UTC 2020 : Method response body after transformations: "Hello from Lambda!"