Skip to main content

AWS S3 Setup

Prime uses AWS S3 to store user-uploaded media files. The backend handles uploads via Multer and streams files directly to your S3 bucket.

1. Create an S3 bucket​

  1. Go to the S3 Console
  2. Click Create bucket
  3. Choose a unique bucket name (e.g. your-app-media)
  4. Select the AWS region closest to your users (e.g. us-east-2)
  5. Uncheck Block all public access if you need publicly readable files, or keep it blocked and use signed URLs

2. Create an IAM user​

  1. Go to IAM → Users → Create user
  2. Attach the policy AmazonS3FullAccess (or a custom policy scoped to your bucket)
  3. Under Security credentials, create an Access key
  4. Copy the Access Key ID and Secret Access Key — you won't see the secret again

Instead of full S3 access, scope the IAM policy to your bucket only:

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject"],
"Resource": "arn:aws:s3:::your-app-media/*"
}
]
}

3. Configure environment variables​

In demo-server/.env:

AWS_ACCESS_KEY=your_access_key_id
AWS_SECRET_KEY=your_secret_access_key
AWS_REGION=us-east-2
AWS_BUCKET_MEDIA_LINKS=your-app-media

How it works​

  • Uploads go through POST /media — Multer buffers the file, then the backend streams it to S3
  • File URLs are stored in the media database table
  • A background job (CLEANUP_UNUSED_MEDIA_CRON) runs nightly to remove orphaned files from S3

CORS configuration (if accessing files from the browser)​

If you need the browser to access S3 files directly, add a CORS rule to your bucket under Permissions → CORS:

[
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET", "PUT", "POST"],
"AllowedOrigins": ["https://yourdomain.com"],
"ExposeHeaders": []
}
]