Upload assets to AWS S3

Anish
May 1, 2021

Every growing business is now days moving to AWS & GCP.

Here we need to configure AWS s3 instance.

first let’s install & import it.

npm install aws-sdk

const AWS = require(‘aws-sdk');

We need to configure it, for our service, try to put this a common place so that entire app can use it, wherever required.

const s3Bucket = new AWS.S3({

accessKeyId: process.env.AWS_ACCESS_KEY_ID,

secretAccessKey:process.env.AWS_ACCESS_KEY_SECRET

});

we can get this access key & secret using aws console.

const params = {

Bucket: process.env.AWS_BUCKET_NAME,

Key: path where we need to store the file on aws bucket,

Body: fileData,

ACL:’public-read’

}

Thanks !!

--

--

Anish

A full-stack technical consultant, fond of learning new technologies, understanding business requirements.