Spring Boot — AWS
A simple guide how we can deploy a spring boot application. I have used free tier of AWS. You can registered by going on website AWS.Its free for 1 year.
If you have any suggestion or if you feel anything needs to be you can give your comment.
Lets begin Step By Step to upload a spring boot application in aws
Creating EC2 instance
Step 1 : Create an EC2 instance .Login to AWS console. We will be using free tier of AWS.
https://signin.aws.amazon.com/
Step 2: Once logged in click on services and select EC2
Step 3 : Click on launch instance
Step 4: There are total 7 step in creation of EC2 instance.
Step 1 : Select AMI.
Step 2: Select instance Type
Click on Next: Configure Instance Details
Step 3 : Choose instance details.
Dont change anything right now , just go to next step.
Click on Next Add Storage.
Step 4: Add Storage details
Don’t change anything Click on Next : Add Tags
Step 5 : We can have multiple tags here.
Here you can store name value pair.
Need to create a security Group
You can create a new security group or you can select an existing security group.I have already created security group call webdmz.
Security group is used to allow which port will be access like for SSH,HTTP and also Custom TCP port where we will access our URL
Following are the step to create security group
Click on EC2 from services. On the right hand side there is Network & Security
We need to create Inbound rules i.e. which port are allowed to access. For outbound rules we wont change anything as we will allow every access.
We created a security group called webdmz.
Step 6: Now configure security group
Select webdmz security group.
Step 7 : Review everything and launch.
So these are the 7 steps which are require to start an EC2 instance.
Step 5: once you click Launch , you will be getting following screen
We need to create key pair , once generated we can use this in next application. If you are doing for the first time from drop down create a new pair.
Give it a name and download it. and now click on Launch instance.
Step 6: you will get the following messages.
Now you can click on View instance
Step 7: if everything is fine. you will get following screen with status as running
Step 8 : Now we need to login on this we can do with putty or terminal (mac). I will explain you through mac.
Open terminal and go to your folder.
We have kept our key file in SSH folder. use above command to login in ec2
cmd 1: CHMOD 400 JavaSpringkey1.pem [Name of your key file]
CMD 2 : ssh ec2-user@[publicip] -i [keyFile].pem
Congratulations you have logged in in your 1st EC2 instance.
We will create a simple Spring Boot Application in eclipse
Step 1: Create a new spring project in eclipse
Just add this method and @RestTemplate
In pom.xml add following
Do maven clean and install. Once this process is completed. there will be a jar file created in target folder.
Now we have EC2 instance created and also our spring boot application is ready. Now we will deploy this application on AWS and will execute the URL
Now we will log in EC2 instance and will deploy the appliction
1 : we will log in EC2 instance.
2 : We will check version of java. It should be same which was used for compiling.
3 : We cant directly transfer our jar to ec2 instance. First we will transfer our file to S3 Bucket and from S3 bucket we will deploy this to EC2.
To install java 1.8 use following command
yum install java-1.8.0-openjdk
and follow the instruction . Once java is installed when you check version
java -version it will show 1.7 we need to set java 1.8 use following command
alternatives — config java
Now we will copy jar file to S3 bucket, we will create 1 bucket
Name of the bucket should be unique.
Once bucket is created we need to upload our jar file in this bucket
upload jar file from target to this bucket
Just click on this file and copy the object url
https://[Name of bucket].s3.amazonaws.com/[Name of the file]
In terminal use
wget [url copied]
now we will run the command to start our application.
java -jar SpringJava-aws-exe.jar
Congratulations you have just deployed your application in AWS.