简体   繁体   English

Lambda代理响应格式错误

[英]Malformed Lambda proxy response

I am trying to access a Lambda function using a POST method. 我正在尝试使用POST方法访问Lambda函数。 When I try to test the POST resource I put in the Request body 当我尝试测试POST资源时,我将其放入Request正文中
{"article_url": "http://technewstt.com/bd1108/"}

This makes the API Gateway respond with Execution failed due to configuration error: Malformed Lambda proxy response My code is below. Execution failed due to configuration error: Malformed Lambda proxy response这会使API网关响应Execution failed due to configuration error: Malformed Lambda proxy response我的代码如下。

exports.handler = (event, context, callback) => {
//event = {"article_url": "http://technewstt.com/bd1108/"};
console.log(event.article_url);
var http = require('http');
var TextAPI = require('textapi');
var textapi = new TextAPI({
    application_id: "randomn numbers",
    application_key: "randomn numbers"
});
textapi.summarize({
    url: event.article_url,
    sentences_number: 3
}, function(error, response) {
if (error === null) {
    response.sentences.forEach(function(s) {
    console.log(s);
    //var body = JSON.parse(s);
    // TODO implement
    //callback(null, s);
    callback(null, {"statusCode": 200, "body":  JSON.stringify(s)});
    });
}

});

}; };

Please note that if I uncomment the second line the API gateway works fine. 请注意,如果我取消注释第二行,则API网关可以正常工作。

Any help with this issue would be greatly appreciated. 任何与此问题的帮助将不胜感激。

You are using Lambda Proxy integration which always expects output of the format http://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format 您正在使用Lambda代理集成,该集成始终期望输出格式为http://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy for lambda输出格式

"Malformed Lambda proxy response" is returned if the lambda response format is unexpected. 如果lambda响应格式意外,则返回“格式错误的Lambda代理响应”。 You can enable logging with full request/responses which should show you the response being returned from lambda. 您可以启用具有完整请求/响应的日志记录,这应该向您显示从lambda返回的响应。 Its likely there was an error in you lambda function which returned an error. 您的lambda函数中可能有一个错误,该错误返回了错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM