How to promisify AWS S3 callbacks

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

We are a technology solutions startup. We started right out of college as a Chatbot service provider and later branched into bespoke software solutions.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store