I gotta say, I’m having immense problems with Lambda promise/callbacks vs running node locally. Wondering if anyone else has had the weeks of headaches we’ve run into.
Running Node 8.10 with Sequelize + RDS Postgres. Locally I’ve got serverless-webpack and serverless-offline working beautifully, everything is great, no issues.
In production it’s just one multi-hour nighmarish debugging session after another. External API calls just never return, sequelize DB calls failing to return, etc. I’m getting consistent timeouts on all sorts of callbacks, tried in every form: callback hell, wrapping in Promises, async/await. Every single one of them fails for no reason, just times out the lambda session.
What is the deal with AWS Lambda stack? Is anyone else running into these issues? It’s a complete nightmare and I really wish I could get any of this to mimic how it runs for me locally.
I’m doing as Buggy says, and my async / await code works just fine. Usually if I have a bug it’s because I’m missing an await. Even TypeScript is not very good at noticing such things.
I would suggest that you console.log() at every major step in your code. Then I would look at cloudwatch to see what the last logged statement was. I have found that I regularly make calls to services or reference variables that don’t exist and the code just exits. Look at you last logged statement and see what happens in your code right after that last console.log(). Also, verify that the lambda hasnt timed out (default is 6 seconds). Your last line in cloudwatch will include how long the function took to execute.
Here is an example of using promises in serverless to read a file: