
I Built a Secure File Sharing System with End-to-End Encryption on AWS: Architecture and Lessons Learned
A student builder's case study of a full-stack file sharing app using React, Spring Boot, Amazon S3, RDS and IAM, with client-side AES encryption and JWT/OTP authentication. Covers the architecture, security decisions and the real bugs I hit during deployment.
Introduction
Cloud storage is easy. Cloud storage you can trust is harder.
For my capstone project, I wanted to answer one question: can I build a file sharing system where even the server never sees the plain contents of a user's file?
This article walks through the architecture I built on AWS, the security decisions behind it, and the real problems I hit while deploying it. If you are a student or early-career builder planning a cloud project, I hope this saves you some time.
Tech stack
Layer | Technology |
|---|---|
Frontend | React.js |
Backend | Java Spring Boot |
Database | MySQL on Amazon RDS |
File storage | Amazon S3 |
Access control | AWS IAM |
Encryption | AES (client-side, Web Crypto API) |
Authentication | JWT + OTP verification |
Deployment | Docker, Render (backend and static frontend) |
The Core Idea: End-to-End Encryption
In a typical upload flow, the file travels to the server and is then encrypted (or not) before being stored. That means the server briefly sees everything.
In my design, the file is encrypted in the browser before it leaves the user's device. The server and S3 only ever handle ciphertext.
Architecture at a glance: Browser (React) → Spring Boot API (JWT + OTP) → Amazon S3 for encrypted files and Amazon RDS for metadata, with an IAM role scoping what the backend can access.
Upload flow
- The user logs in and receives a JWT.
- The browser encrypts the file with AES using the Web Crypto API.
- The encrypted file is sent to the backend and stored in Amazon S3.
- File metadata (owner, name, timestamps, sharing details) is stored in MySQL on RDS.
Download flow
- The user authenticates and requests a file.
- The backend verifies the JWT and ownership or sharing permissions.
- The encrypted file is returned and decrypted in the browser.
Design Decisions Worth Explaining
1. Why split storage between S3 and RDS?
S3 is built for durable, scalable object storage. RDS is built for relational queries. Keeping files in S3 and metadata in MySQL lets each service do what it does best, and keeps large binary data out of the database.
2. Why JWT plus OTP?
A password alone is a single point of failure. The OTP step adds a second factor, and JWTs let the backend stay stateless: every request carries a signed token that the
JwtFilter validates before the controller runs.3. Why IAM roles and least privilege?
The backend should only be able to do what the app needs: read and write objects in one specific bucket. Scoping the IAM policy to that bucket means a leaked credential has a far smaller blast radius than one with full S3 access.
Example of a scoped policy:
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": ["s3:PutObject", "s3:GetObject", "s3:DeleteObject"], "Resource": "arn:aws:s3:::your-bucket-name/*" } ]}Keep the bucket itself private, with Block Public Access enabled.
Lessons Learned: The Bugs That Taught Me the Most
The architecture looked clean on paper. Deployment is where the real learning happened.
Problem 1: The app could not connect to RDS
Symptom: The backend timed out connecting to the database.
Cause: The RDS security group was only allowing connections from a specific IP address, so the deployed backend was blocked.
Fix: Review the inbound rules on the database's security group and allow the correct source on port 3306. For a production setup, place RDS in a private subnet and allow traffic only from the application's security group, rather than opening it broadly.
Problem 2: Authentication kept failing
Symptom: Requests that should have been authenticated were rejected.
Cause: Issues in the
JwtFilter logic, meaning how the token was extracted, validated and applied to the security context.Fix: Log each stage of the filter (header present, token parsed, signature valid, user loaded), and make sure public endpoints like login and OTP verification are excluded from the filter.
Problem 3: Encryption worked locally but failed once deployed
Symptom: The Web Crypto API threw errors in the deployed app.
Cause:
window.crypto.subtle is only available in secure contexts, meaning HTTPS (or localhost). Over plain HTTP, it is undefined.Fix: Serve the frontend over HTTPS. This is a good reminder that browser security features can behave differently between development and production.
Problem 4: CORS errors
Symptom: The browser blocked API calls from the frontend to the backend.
Cause: The backend did not allow the frontend's deployed origin.
Fix: Configure CORS in Spring Boot to allow your specific frontend origin, the needed methods and the
Authorization header. Avoid wildcard origins when credentials or tokens are involved.Problem 5: Environment variables did not map correctly
Symptom: The app started locally but failed on the hosting platform.
Cause: Spring Boot properties (like
spring.datasource.url ) need to be mapped from the platform's environment variables, and the names must line up.Fix: Define variables using Spring's relaxed binding (for example,
SPRING_DATASOURCE_URL ), and keep secrets out of the repository.Containerizing the Backend
I packaged the Spring Boot service with a multi-stage Dockerfile: Maven builds the JAR in the first stage, and only the JAR is copied into a slim Eclipse Temurin JRE image in the second.
# Stage 1: buildFROM maven:3.9-eclipse-temurin-17 AS buildWORKDIR /appCOPY pom.xml .COPY src ./srcRUN mvn clean package -DskipTests
# Stage 2: runFROM eclipse-temurin:17-jreWORKDIR /appCOPY --from=build /app/target/*.jar app.jarEXPOSE 8080ENTRYPOINT ["java", "-jar", "app.jar"]Why multi-stage? The final image has no Maven, no source code and no build cache. It is smaller, faster to deploy and has a smaller attack surface.
What I Would Improve Next
Being honest about limitations is part of good engineering. Next steps for this project:
- Pre-signed URLs so large files move directly between the browser and S3
- S3 server-side encryption (SSE-KMS) as a second layer on top of client-side encryption
- Private subnets for RDS with security group to security group rules
- AWS Secrets Manager for database credentials and signing keys
- Rate limiting on the login and OTP endpoints
- CloudTrail and CloudWatch alarms for auditing and alerting
- A CI/CD pipeline to automate build and deployment
Key Takeaways
- Design security in from the start. Encrypting on the client changes your whole architecture.
- Least privilege is a habit. Scope IAM policies and security groups to exactly what is needed.
- Dev and prod differ. HTTPS requirements, CORS and environment variables only bite when you deploy.
- Debug systematically. Check one layer at a time: network, authentication, application.
- Document your failures. The bugs taught me more than the successes.
Conclusion
Building this project taught me more about AWS, security and deployment than any single tutorial. If you are a student looking for a portfolio project, building something with real authentication, real storage and real encryption is a great way to learn.
Have you built something similar, or have suggestions for improving the design? Share them in the comments. I would love to learn from you.

Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article