Since AWS released support for Node v8.10 in Lambda, I was able to refactor Lambda API to use async/await
instead of Bluebird promises. The code is not only much cleaner now, but I was able to remove a lot of unnecessary overhead as well. As part of the refactoring, I decided to use AWS-SDK’s native promise implementation by appending .promise()
to the end of an S3 getObject
call. This works perfectly in production and the code is super compact and simple:
1 |
let data = await S3.getObject(params).promise() |
The issue came with stubbing the call using Sinon.js. With the old promise method, I was using promisifyAll()
to wrap new AWS.S3()
and then stubbing the getObjectAsync
method. If you’re not familiar with stubbing AWS services, read my post: How To: Stub AWS Services in Lambda Functions using Serverless, Sinon.JS and Promises.