Category: java
Deploying Spring Boot to AWS
Published on 16 Jul 2026
Explanation
Before deployment, package the Spring Boot application into an executable JAR file using Maven. This JAR contains the application and embedded Tomcat server.
Code:
mvn clean package
Explanation
Launch an AWS EC2 instance, connect to it using SSH, and install Java. The EC2 instance will host the Spring Boot REST API.
Code:
sudo apt update sudo apt install openjdk-21-jdk
Explanation
Upload the generated JAR file to the EC2 instance using SCP or any file transfer tool.
Code:
scp target/student-api.jar ubuntu@EC2_PUBLIC_IP:/home/ubuntu/
Explanation
Run the Spring Boot application on the EC2 instance using the java -jar command. The embedded Tomcat server starts automatically.
Code:
java -jar student-api.jar
Explanation
Open the application port (for example, 8080) in the AWS Security Group. Clients can then access the REST API using the EC2 public IP address.
Code:
http://EC2_PUBLIC_IP:8080/students