A simple Node.js and React project for uploading images to an Amazon S3 bucket. This project demonstrates secure handling of AWS credentials and environment variables.
- Upload images directly to AWS S3.
- Uses
.env
files for managing environment-specific variables. - Prevents secrets from being committed to the repository.
project-root/
├── react-app/
├── uploadtoS3/
│ ├── .env # Contains AWS secrets (not committed to Git)
│ ├── .gitignore # Specifies files to ignore for Git
│ └── src/ # Application source code
├── .gitignore
├── package.json
└── README.md
- Node.js and npm installed.
- An AWS account with access to an S3 bucket.
-
Clone the Repository
git clone https://github.com/ichiragkumar/UploadImagesTos3.git cd UploadImagesTos3
-
Install Dependencies
npm install
-
Set Up Environment Variables Create a
.env
file in theuploadtoS3/
directory with the following contents:AWS_ACCESS_KEY_ID=your-access-key-id AWS_SECRET_ACCESS_KEY=your-secret-access-key AWS_REGION=your-region S3_BUCKET_NAME=your-bucket-name
-
**Add
.env
to **.gitignore
Ensure.env
is ignored to prevent committing secrets:- In
uploadtoS3/.gitignore
:.env
- At the root level, ensure
.gitignore
also includes:uploadtoS3/.env
- In
-
Remove
.env
from Git History If.env
was accidentally committed, remove it:git rm --cached uploadtoS3/.env git commit -m "Remove .env from version control" git push origin main --force
If you need to completely purge it from history, use:
bfg --delete-files .env git reflog expire --expire=now --all git gc --prune=now --aggressive git push origin main --force
-
Start the Application Navigate to
uploadtoS3/
orreact-app/
and run:npm start
-
Upload Images Follow the interface prompts to upload images to your configured S3 bucket.
- Do not hardcode secrets in your code.
- Use a secret manager like AWS Secrets Manager for production.
- Rotate AWS credentials periodically.