DEV Community

Discussion on: Unit Testing AWS Lambda Functions in Node.js

Collapse
 
grunlowen2 profile image
grunlowen2

Thanks for the suggestions here. I implemented something similar after reading this, but I'm wondering if there is really a need for the promise. In my case, what I did was create an exports.deps that returns an object like { s3: new AWS.S3() } and then I also created an exports.initDeps, which gets the object from exports.deps, and then assigns it to the top level variable. I have a fairly complex lambda, and I wanted to be able to test functions independently. So now the handler is the only function that calls exports.deps, and in my test code I overwrite initDeps, and then call any of the functions.