In this Post we are going to create a simple hello world Spring Boot Application and Deploy, Run the same AWS EC2 using AWS S3 bucket.
So lets first create a Simple hello world Spring Boot Application using https://start.spring.io/, Download the zip, extract and import the same in your IntelliJ Idea IDE. Here I have created a simple spring boot project using Gradle build.
Now run ./gradlew bootJar command to generate the jar file. You can find this generated jar file at build/libs location.
Now login to AWS Console and go the AWS EC2 Dashboard we will create an EC2 instance in our Free Tier.
Click on Launch Instance
Now in the Next Page create an EC2 Instance which eligible in Free Tier as show below:
It will ask for a key so create a new key for our EC2 Instance as we going use Putty so we will select .ppk file to generate our key as shown below:Note: .ppk key will be downloaded to our Downloads.
Now Launch the EC2 instance using the newly created key, our EC2 instance will be created and launch successfully.
Now Lets Connect to our newly created EC2 instance using Putty tool, For this go Click on EC2 instance ID, you able to see Connect option there, Click on Connect.
Open Putty and create a new Session using the EC2 Host and Save it
Next set the Auth key using .ppk file downloaded and click on Open.
We will be able to connect our newly create EC2 instance through Putty
Now Switch to root user using Command
[ec2-user@ip-172-31-0-223 ~]$ sudo -i
[root@ip-172-31-0-223 ~]#
We have created our Spring Boot application on Java17. So to run our application inside EC2 instance JDK 17 version should be present in our EC2 instance. So let us check the java version available in our EC2 instance. We can see Java is not available in our newly created EC2 instance.
So we need to install JDK17 in our EC2 instance , we will be installing java-17-amazon-corretto using below command
sudo yum install java-17-amazon-corretto-devel
Next Step is to create a Amazon S3 bucket and Upload our Spring Boot Application jar file there.
Go to AWS Console and search for S3 Service , you will be able to find S3 Dashboard
And create a S3 bucket, here you can Enable the ACL to make the bucket accessible public and leave all other settings a default and Click on Create Bucket.
We will be able to create a S3 bucket Successfully:
Now its time to upload our Spring Boot Application jar file to our S3 bucket, Go to S3 Upload page, Select your jar file from your system location and click on Upload button.
Our Jar file will be uploaded successfully, Copy the Object Url
Next IN order to Access our S3 bucket from our EC2 instance we need Make Public Access and make our S3 Bucket Accessible to Public


Now again, wget the S3 Object Url , this time it will be downloaded successfully
Now run java -jar helloAws-0.0.1-SNAPSHOT.jar, We can see our Spring Boot Application Starts successfully in our EC2 instance.
Now go to EC2 instance Security Group and add the Inbound rules to allow port 8080
Next go EC2 Instance summary page and copy the Public IPv4 DNS URL
Now its time test our Spring Boot Application running inside our AWS EC2 Instance,
http://ec2-43-204-107-144.ap-south-1.compute.amazonaws.com:8080/hello
Summary:
Congratulations! In this Demo We have successfully Deploy and Run Spring Boot Application in AWS EC2 instance using AWS S3. We have used Putty to get connect to our EC2 instance from Windows System.
Ref: https://docs.aws.amazon.com/corretto/latest/corretto-17-ug/amazon-linux-install.html
0 Comments