A secure RESTful API built with Spring Boot featuring JWT-based authentication, deployed to AWS cloud infrastructure.
- User signup with secure password storage (BCrypt)
- User login with JWT token generation
- Token-based authentication middleware
- AWS deployment: EC2 instance + RDS MySQL database
- Full CRUD operations (Create, Read, Update, Delete)
- Exception handling and input validation
- Unit tests with Mockito
- Backend: Spring Boot 3.x, Spring Security, Java 25
- Database: MySQL 8.0 on AWS RDS
- Deployment: AWS EC2 (t3.micro), RDS (db.t3.micro)
- Security: JWT tokens, BCrypt password hashing, Spring Security
- Testing: JUnit 5 & Mockito
- JDK 17+
- MySQL 8.0+
- Maven 3.6+
- Git
- Clone the repository
git clone https://github.com/Dilangi/Spring-Boot-Demo.git
cd spring-boot-demo- Configure local database
# Create database
mysql -u root -p
CREATE DATABASE springboot_demo;- Update application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/springboot_demo
spring.datasource.username=<YOUR_USERNAME>
spring.datasource.password=<YOUR_PASSWORD>
server.port=4999- Build the project
mvn clean package- Run the application
mvn spring-boot:run- MySQL connection error → ensure MySQL is running
- JWT Unauthorized → check Authorization header format
- AWS account
- EC2 instance (Amazon Linux)
- RDS MySQL database
- EC2 and RDS in the same VPC
- Port 4999 open on EC2
- Port 3306 open from EC2 → RDS
- Connect to EC2
cd <KEY_FILE_LOCATION>
ssh -i <YOUR-KEY.pem> ec2-user@<EC2_PUBLIC_IP>- Install Java & Maven
sudo dnf install -y java-17-amazon-corretto mavenVerify
java -version
mvn -version- Clone and build project
git clone https://github.com/Dilangi/Spring-Boot-Demo.git
cd Spring-Boot-Demo/demo
mvn clean package - Update application.properties for AWS
spring.datasource.url=jdbc:mysql://<RDS-ENDPOINT>:3306/demo_db
spring.datasource.username=<RDS_USERNAME>
spring.datasource.password=<RDS_PASSWORD>
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=false
server.port=4999
server.address=0.0.0.0 - Run application on EC2
java -jar target/spring-boot-demo-0.0.1-SNAPSHOT.jar- API Not Reachable (ECONNREFUSED) → Ensure inbound rule in EC2 Security Group are correct
- Unknown Database Error → Ensure Database schema is created in RDS
POST /api/v1/auth/register- Register new userPOST /api/v1/auth/login- Login and receive JWT token
POST /api/v1/user/addUser- CreateGET /api/v1/user/getUsers- ReadPUT /api/v1/user/updateUser/{id}- UpdateDELETE /api/v1/user/deleteUser/{id}- Delete
curl -X POST http://localhost:4999/api/signup \
-H "Content-Type: application/json" \
-d '{"username":"user","password":"password123"}'curl -X POST http://localhost:4999/api/login \
-H "Content-Type: application/json" \
-d '{"username":"user","password":"password123"}'Response:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}curl -X GET http://localhost:8080/api/users \
-H "Authorization: Bearer YOUR_JWT_TOKEN"Use Postman or cURL to test endpoints. Include JWT token in Authorization header:
Authorization: Bearer <your-jwt-token>
Run all tests:
mvn test
Run a single test:
mvn -Dtest=AccountServiceTest test- Fully implemented RESTful API with JWT-based authentication and authorization
- Secure user authentication using Spring Security and BCrypt
- Deployed and tested in a cloud environment using:
- AWS EC2 for application hosting
- AWS RDS (MySQL) for persistent data storage
- VPC & Security Groups for controlled network access
- Includes CRUD operations, input validation, and structured error handling
- Unit-tested using JUnit and Mockito to ensure reliability and maintainability
🚧 Deployment Availability
- The application has been successfully deployed and verified on AWS
- To minimize ongoing cloud costs, the live environment is currently stopped
- The application can be redeployed on demand within minutes
- Implement role-based access control (RBAC)
- Add input validation across all endpoints
- Implement refresh token mechanism
Dilangi Thilakarathna
LinkedIn