-2

I am trying to use Amazon S3 to upload/download some images and videos from inside my locally running NodeJS application. But when I search for that, there are tons of different code snippets and different credential management approaches and I am totally confused by that.

I created an IAM user and I have AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_BUCKET_NAME in my .env file but I think it's not a good approach using .env file in my app and it's better I use temporary token credentials. But I don't know how?

What is the minimum secure code I can use to do that?

best_of_man
  • 643
  • 2
  • 15
  • You could also make use of environmental variables? I am not sure if any similar libraries exist, but try looking for encrypted credentials, similar to RoR for NodeJS. Basically, it encrypts your details in a credentials.yml.enc file, which can then be access via the Rails helper. – Ashvith Shetty Jan 28 '23 at 00:43
  • @AshvithShetty: So you say using a `.env` file for credentials is a common way of doing that? – best_of_man Jan 28 '23 at 00:45
  • What I was trying to say is that most platforms also have option to set environmental variables without the need for .env file, which can then be accessed by the web app you've deployed. – Ashvith Shetty Jan 28 '23 at 00:48
  • @AshvithShetty: Right! But I am trying to take this approach: https://docs.aws.amazon.com/sdk-for-java/v1/developer-guide/prog-services-sts.html , Although I am completely new to AWS and have no idea what I should to do? – best_of_man Jan 28 '23 at 00:49

1 Answers1

2

Read the AWS SDK for JavaScript V3 Developer Guide. There are many examples and yes - using creds is a standard practice.

What's the AWS SDK for JavaScript?

A topic you should read is https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials.html

smac2020
  • 9,637
  • 4
  • 24
  • 38
  • I followed your suggested links but they're for Java not Java/TypeScript. – best_of_man Jan 28 '23 at 01:25
  • These links are for JavaScript - not Java. There is a NodeJS topic in the guide I linked too as well -- https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/node-js-considerations.html – smac2020 Jan 28 '23 at 01:28
  • At `Next steps` section of https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/setup.html#setup-credentials it builds something in Java. I don't know what to do if I use JavaScript? Also in other JS/NodeJS related links I can not see something similar to these steps! – best_of_man Jan 28 '23 at 01:36
  • Why are you referring to the Java DEV Guide? Your thread says you want to work in NodeJS. You should be reading the JavaScript V3 DEV guide. The creds section in the JavaScript guide is here -- https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/setting-credentials.html – smac2020 Jan 28 '23 at 01:43
  • `Loading credentials in Node.js from IAM roles for Amazon EC2` `Loading credentials for a Node.js Lambda function` `Loading credentials in Node.js from the shared credentials file` `Loading credentials in Node.js from environment variables` `Loading credentials in Node.js using a configured credential process` – best_of_man Jan 28 '23 at 02:00
  • Which one is the better approach? – best_of_man Jan 28 '23 at 02:02
  • 1
    I personally use shared creds in my AWS programs. That is, a credentials file that have my keys, – smac2020 Jan 28 '23 at 02:05