0

I am trying to send data to my lambda function however the function is not getting my data, the event variable is empty. I am not getting any errors and when I test the function in my API Gateway it works fine. So I am not sure what is happening. My code for sending data to Lambda is below.

var options = { 
    method: 'POST', 
    url: 'correct api url', 
    contentType: "application/json",
    dataType: "json",
    data: s
}

for data: s within my console looks like this data: '{"article_url":"a url here"}'

Any idea what the problem is?

4
  • Are you using pass-through or a specific API Gateway mapping template? If you have a mapping template, please include it in your question. Commented Aug 31, 2017 at 12:45
  • @MarkB no template so I would assume it's a pass through Commented Aug 31, 2017 at 13:37
  • Are you sending the entire event object to the log and verifying that it is totally empty? Commented Aug 31, 2017 at 16:57
  • @MarkB correct the entire event is empty Commented Aug 31, 2017 at 19:01

1 Answer 1

0

In the "Integration Request" configuration, make sure you've checked the "Use Lambda Proxy integration" checkbox.

And make sure your output matches the schema defined here to avoid errors:

http://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-set-up-simple-proxy.html#api-gateway-simple-proxy-for-lambda-output-format

{
    "isBase64Encoded": true|false,
    "statusCode": httpStatusCode,
    "headers": { "headerName": "headerValue", ... },
    "body": "..."
}
Sign up to request clarification or add additional context in comments.

9 Comments

When I do that I get the error Execution failed due to configuration error: Malformed Lambda proxy response
Here is my callback from the lambda function callback(null, {"statusCode": 200, "body": JSON.stringify(response.sentences)}); is it that the headers are missing as to why it is saying the JSON is malformed?
That is likely the issue. You're going to need the header indicating that your payload is application/json
ok changed this to a test and it is still getting the error Execution failed due to configuration error: Malformed Lambda proxy response my test response is callback(null, {"statusCode": 200, headers: {"Content-Type": "application/json"}, "body": {'testing':'test'}});
Body is not a valid JSON string. Try stringifying that {testing} object.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.