How to promisify AWS S3 callbacks

OrderStack
2 min readDec 28, 2020

Have you ever come across situations in your code where you thought that if this function returned a promise, things could’ve been so much easier?

Well, we came across such issues while we were using AWS S3 storage and we thought of making our lives simpler by making an npm package!

Our CTO and Co-Founder, Rohan Dhamapurkar, got thinking and made s3Helper, an npm package which promisifies all the callbacks from AWS S3.

You can find the s3helper package here.

How to use s3Helper:

You need to first install the s3Helper package by typing the following command in the CLI:

npm i @orderstack/s3helper

After the package is installed, you just need to require the package and use it. Require and use as below:

let s3helper = require("@orderstack/s3helper")let s3HelperFunctions = s3helper({  S3_CONN_CONFIG: {    accessKeyId: accessKeyId,    secretAccessKey: secretAccessKey,    region: region,  },  BUCKET_NAME: bucketName,})

There are three functions which can be used from this package:

  1. uploadFileData: This function takes in an object with 2 fields, namely, Body and Key. The Body will contain the body of the data and the Key will contain the name by which your file will be stored. For more information, check the AWS S3 documentation.
s3HelperFunctions.uploadFileData({  Body: Body,  Key: Key,})

2. getURLForDownload: This function takes in an object with 2 fields namely, Expires and Key. The Key will contain the name by which your file will be stored and Expires is the number of seconds after which the link should expire. For more information, check the AWS S3 documentation.

s3HelperFunctions.getURLForDownload({  Key: Key,  // default expiry 1 days unless explicitly passed  Expires: expiry,})

3. getURLForUpload: This function takes in an object with 2 fields namely, Expires and Key. The Key will contain the name by which your file will be stored and Expires is the number of seconds after which the link should expire. For more information, check the AWS S3 documentation.

s3HelperFunctions.getURLForUpload({  Key: Key,  // default expiry 1 days unless explicitly passed  Expires: expiry,})

If we missed out on something you were looking for, drop down a message on our social media handles:

Facebook: OrderStack
Instagram: orderstack
Twitter: @orderstack

--

--

OrderStack

At OrderStack, we bring to you an augmented tech team that sells engineering as a service! We work with start-ups to build bespoke MVPs.