Connect to AWS S3 bucket from Nodejs app persistent connection required

0 votes

I want to connect to AWS S3 using a nodejs/express app.

I do have a temporary plan to connect with you,
environmental data

aws_access_key_id=XXX
aws_secret_access_key=XXXX/
aws_session_token=xxxxxxxxxxxxxxxxxxxxxxxxxx

S3-connection-service.js

const AWS = require("aws-sdk");

AWS.config.update({
    accessKeyId: `${process.env.aws_access_key_id}`,
    secretAccessKey: `${process.env.aws_secret_access_key}`,
    sessionToken: `${process.env.aws_session_token}`,
    region: `${process.env.LOCAL_AWS_REGION}`
});

const S3 = new AWS.S3();

module.exports = {
    listBucketContent: (filePath) =>
        new Promise((resolve, reject) => {
            const params = { Bucket: bucketName, Prefix: filePath };
            S3.listObjects(params, (err, objects) => {
                if (err) {
                    reject(err);
                } else {
                    resolve(objects);
                }
            });
        }),
       ....
       ....
 }

controller.js

   const fetchFile = require("../../S3-connection-service.js");

   const AWSFolder = await fetchFile.listBucketContent(filePath);

Fine it's works and I'm able to access S3 bucket files and play with it.

PROBLEM

The connection is not stable, which is the issue. I have to copy and paste the new tokens into the env file and restart the node programme because when I use session token, the connection stays active for a while and fresh tokens are generated again after a while.

Really, I don't know how to make a connection persistent.

Where should I keep my AWS secrets and confidential information, and how can I connect to S3 while keeping the connection active?

Dec 23, 2022 in AWS by Tejashwini
• 3,820 points

edited 6 days ago 10 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP