Now that our application is running perfectly in the local environment, lets move it to the cloud. My preferred choice for cloud provider is AWS since its widely used and provides with 12-month of free usage.
Setting the cloud Infrastructure
I am assuming that you will an account in AWS and logged into it. If not, then it is really easy to setup the account. And yes, if you are creating an account for the first time, you will be needing a credit/debit card since it will use it for verification purposes. You will see a small amount debited, which will be refunded the next day once the account creation is successful.
Now that you are logged into your AWS account, we will be going to our server which will host our application. Creating it is simple, just navigate to EC2 from search bar.
Open it and click on launch instance, You will see this.
Given any name you want to your server.
Select Ubuntu from Application and OS images and keep the default as is.
Keep the instance type as t2.micro as it is free tier eligible.
For key-pair, if you already have one, select that. If not click create new pair
and create one by keeping the defaults as is.
Keep the network settings default too. Make sure that Allow SSH traffic from
is enabled and Anywhere
is selected.
Now click on launch instance
to create your server. You will see this once the creation is successful.
Once created, wait till you see your status check
as 2/2 checks passed
. This confirms that the server is now fully up and running.
Now lets log into the server and deploy our applicatio. Click on the server and then click on connect.
You will see any options. Do the following if you are:
- a Windows user, setting the permission on the key is a tricky process, so we will use the EC2 Instance Connect option.
- a Linux/Mac user, open the SSH client option and follow through the steps.
Once connected, you should be able to see this.
Run sudo apt update
command to update the packages for the server.
Before cloning your repo, you will first need to install java. We wont be installing maven as the repo has a mvnw
executable, which a maven wrapper. Install java using the following command:
sudo apt install openjdk-21-jre-headless -y
sudo apt install openjdk-21-jdk-headless -y
Once installed, clone the repo and cd into it. Make the mvnw
executable by using the following:
sudo chmod +x mvnw
One more step and we are done, just enter the API key in the application.properties
file and save it. Now just enter the command to run the application.
./mvnw spring-boot:run
Once you run that command, you will see successful execution. You will be thinking now if I open the browser and type localhost:<PORT>
, I should be able to see the application running. Well, the short answer is no since you are running a different machine.
To access it, you need to enter the server's public IP followed by the port number to access it. Type the public IP address (which you can find at the homepage on Instance), followed by the port number in the browser. You still won't see the application since by default our server blocks any incoming connection to it on that port. To allow them, we need to edit its network rules.
This can be done by editing the security group of the instance. You can find the security group of the instance in its security tab. For me it is launch-wizard-4
.
Open the security group and then click on edit inbound rules
.
Click on add rule
, keep the type as Custom TCP
, Port range as your port number
(I have kept mine as 8001
since thats the port which my application uses), Source as Anywhere
and click on search bar next to it and select the CIDR range as 0.0.0.0/0
and Save rules
Once you are done, you should see the added rule, and now your app should be opening.
In part 3 we will be discussing the automation process.
Top comments (0)