A Promise example

Hi guys,

I’ve been learning JS Promises since I am writing up a complex multistage video ingestion process at work that I think would benefit from this structure.

I noticed https://github.com/serverless/examples/blob/master/aws-node-fetch-file-and-store-in-s3/handler.js#L5 uses “bluebird” promises. Can I ask why? I think node4.3 supports Promises natively.

I tried to summarise my learnings here: https://github.com/kaihendry/lambda-promises/blob/master/handler.js

Be great if a more seasoned developer could critique this code. With thanks,

Support for NodeJs 4.3 is a relatively recent thing in Lambda - it wouldn’t have been an option when Serverless v1.0 was being developed.

Bluebird also has some nice features that aren’t in the native promise implementation (e.g. coroutines, etc), which is another reason to use it…

1 Like

So in summary you need to return the promise with a callback to deliver the response?

You don’t even need to return it, but it’s good practice to do it.