0

I am having trouble making the callback in lambda to send a response in API Gateway. I am trying to build a simple application that interacts with a MySQL database. Relevent code snippet is below.

The issue is that even though validateToken will return an error and I will see the console.log message the done/callback will never send the expected response to the api gateway and will continue to process any code after it.

exports.handler = (event, context, callback) => { const done = (err, res) => callback(null, { statusCode: err ? '400' : '200', body: err ? err.message : JSON.stringify(res), headers: { 'Content-Type': 'application/json', }, }); if (event.path.match(/myApi\/workers\/*/)) { // Validate Token token.validateToken(pool, event.headers, function(err, result) { if (result.status == 'error') { console.log('Made it to here') done({"message": "Invalid api-token"}, null); } else { // Proceed with fetching workers } }); } } 

Any help would be greatly appreciated!

3
  • Does the function work in the Lambda test console? How long does the function take to process? Commented Jun 12, 2017 at 14:11
  • It works as in it doesn't throw an error but it also doesn't return the "Invalid api-token" as it is expected to. I have been doing most of my testing through the API Gateway tester in the console. Ran a test through the Lambda one as well for this. Commented Jun 12, 2017 at 19:19
  • Sorry forgot to answer your "how long does it take to process" question. It currently times out since it doesn't ever return. Commented Jun 13, 2017 at 15:17

1 Answer 1

0

Turn out my problem was the same that was posted here.

AWS Lambda function never calls the callback

I tried to simplify the code by removing the mysql part and didn't realize that was what was causing the issue.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.