【问题标题】:Malformed Lambda proxy response格式错误的 Lambda 代理响应
【发布时间】:2017-08-30 18:18:49
【问题描述】:

我正在尝试使用 POST 方法访问 Lambda 函数。当我尝试测试放入请求正文中的 POST 资源时
{"article_url": "http://technewstt.com/bd1108/"}

这使得 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)});
    });
}

});

};

请注意,如果我取消注释第二行,API 网关可以正常工作。

对于这个问题的任何帮助将不胜感激。

【问题讨论】:

  • 如果你取消注释第二行,它工作正常。第二行覆盖了传入的事件,这让我问原始事件参数是什么样的?

标签: node.js lambda aws-lambda aws-api-gateway


【解决方案1】:

您正在使用 Lambda 代理集成,该集成始终需要http://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html#api-gateway-simple-proxy-for-lambda-output-format 格式的输出

如果 lambda 响应格式异常,则返回“格式错误的 Lambda 代理响应”。您可以使用完整的请求/响应启用日志记录,这应该向您显示从 lambda 返回的响应。您的 lambda 函数中可能有一个错误,它返回了一个错误。

【讨论】:

    猜你喜欢
    • 2020-04-20
    • 2017-09-28
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 2018-06-03
    • 2021-01-08
    相关资源
    最近更新 更多