简体   繁体   中英

Malformed Lambda proxy response

I am trying to access a Lambda function using a POST method. When I try to test the POST resource I put in the Request body
{"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.

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.

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

"Malformed Lambda proxy response" is returned if the lambda response format is unexpected. You can enable logging with full request/responses which should show you the response being returned from lambda. Its likely there was an error in you lambda function which returned an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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