How to Deploy Your Spring Boot Application on AWS Using EC2 Instance | A | EC2| Spring Boot App

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone Ravi this side welcome to engineering adaa today in this video we are going to discuss how we can deploy a spring boot application on AWS Cloud using ec2 instance so this is the agenda of today's video before going to do the real deployment what I want to tell you that you should have installed this two tools on your system so these are the prerequisite you should have installed the puty and V CP tool on your system so make sure you install this puty and V CP on your system I will provide you the link of this puty andv CP in the description of this video so this is about the introduction of the video now let me try to come out of this slide and go to the intell and try creating one springb application and after that we'll try to see how we can deploy that so let me try to open the intellig here and just wait for a few second uh we'll try to create one springut application and in the springut application we are just going to Simply create a simple springut application uh we are not going to include the database and other thing simply going to create springut application create One controller there and try to create one simple API Okay so I have already opened the int now I'm going to the file new and go to the project go to the spring installer and here just provide the project name okay so let's say it is a spring boot or you can say AWS or you can say yeah AWS spring boot demo okay okay select the M here and the jdk version okay so let's say the Java version that we are going to use is 17 and the jar is there now go next and here let me try to select the longb and is spring web as well so only these two dependency we are going to use we are not going to work with the database okay so just create this application and open in a new tab and just wait for a few second to do the configuration now here you can see it is uh creating the git repository it will try to download the necessary dependency that we have added and once it is done uh we can go to the source and try creating our application here okay so yeah I think the things are good now try to create One controller here so just right click on it go to the new and let's say we are going to create the controller package and let's say the name of our controller class is demo controller or something like AWS demo controller okay now let me try to annotate this class with at theate rest controller and we are just going to create one G mapping here and let's say it is saying that AWS or yeah let's say it is aw and just create one method called public return type of the method is string let's say get display okay we are not going to pass anything and we are just simply returning something from here okay so so let's say it is uh our first deployment on AWS ec2 is successful okay so this is what we are returning from this API now before going to uh do anything let me try to run this application and try to hit this API and then see if it is working fine or not so our application is going to start in a few second let me try to hit this from the browser so our application would be starting on the port number 8080 so and the API that we have created is for/ AWS so just come here paste it out here you can see our application it is started and it is started on the port number 8080 which is a default port for the spring Boot and the API that we are going to hit is for/ AWS now hit it and then see here you can see we are able to see the result here our first deployment on AWS ec2 is successful so our API is working fine now what we are going to do is we are going to create the jar out of this application and then will deploy this application on the AWS using ec2 okay so as of now uh let me try to go to the m one and try to run the my one command here let's say my one clean install and once we'll try to clean install our application it will try to build our application as well and it will generate the jar for us okay so so just wait for a few second once the jar is ready what we'll do we'll try to go to the EC uh AWS and there I will show you how you can create a E2 instance if you don't know how to create a E2 instance uh there is a video on my channel you can go and watch it out so I will try to create a E2 instance there and then uh with the help of puty we'll try to connect to that E2 instance if something is required we will try to uh do the necessary configuration in the ec2 instance and then with the help of VP we'll try to move our jar from our local to E2 instance okay so you can see the build is success and uh here you can see we have the target folder if you go inside the target folder you'll find this jar okay so the jar name is uh AWS _ springbot _ demo and then snapshot version and then snapshot let me try to rename this J okay so this look big to me now let me try to go to this pom.xml file and inside the build you can provide the final name here and in that you can put the name of the jar that you want to create so let's say it is AWS demo and let me try to build this application again so go to this MAV one and try to run the clean install again so it will try to uh create a jar in the Target folder with this name okay so just wait for a few second and here you can see and inside this target folder you can see our jar is created with the name AWS hyphen demo so so we are good now now let me try to go to the AWS and let me try to create a ac2 instance so go to the services and here in the compute you will find this E2 go to the E2 and try to create one ec2 instance here so as of now you can see I don't have any instance up and running so the instance is zero and everything look good to me now go here and launch the instance okay now if you want to provide the name of your instance you can provide it here let's it is uh springboard AWS demo and here you have to select the Ami Amazon machine images we are going to select this Amazon Linux and these are the configuration of that now we are going to select this free tab eligible one and here I'm just going to create a new key PA to connect this cc2 instance from our local machine using puty okay so for that only you need to create a new keep here I don't have any keeper existing so just create a new keier if you have anyone you can select it out so just let me try to create a keyer here and we are going to uh connect like we are going to use this keyer from the puty so just select this PPK file for use with the puty and this is the RSA you have to provide and let me try to provide the keyp name so let's say it is a spring boot AWS key pair something like that and I'm not sure if it is allowed or not let me try to create it and here you can see uh we have created our key PA and it is downloaded there so once it is downloaded make sure you keep it at some safe place so that you can use it later on so let me try to keep it somewhere else so just let me try to okay white ising let me try to cut it from here and put it somewhere else on the desktop I have created 1 AWS folder let me try to go there let me try to create one folder here and uh just keep this inside that okay so we are good now uh what we did we have created our instance as sorry key pair and if you'll go down uh just uh don't change anything here in the security and all just go down and just try to launch the instance it will take few second and it will launch your instance uh yeah you can see successfully initiated launch of instance now if you'll click on this instances you will go to the place where you can see your instance so here you can see your instance is created and the instance state is pending in few second it will be going to running in state from pending state so just wait and yeah once it is up and running you can see it is started like it is in the running State now if you select this instance you'll find more information related to the instant uh downside let me try to refresh this page okay all the information are uh like related to this instance is being given here and if you select it out you'll find more information here you can see let me try to maximize this so you can see the more information related to this instance is coming here you can see the details St status and Alarm Monitoring security network storage and tags if you'll go to the details uh you will find this public IP V4 DNS so just copy this uh this is what you're are going to use when you're going to hit this uh like when you're going to hit this easy to instance from the public domain so copy this and keep it somewhere so let me try to open a notepad here and just just let me try to paste it here so this is uh nothing but this is a public do public URL from where you can access your E2 instance or you can say your application that you're are going to deploy on your ec2 instance okay so just keep it somewhere safe now our our instance is created and we already have created our jar of our application so we have both ready now what we are going to do is uh we are going to connect our E2 instance through the put t Okay so just let me try to open the put T here and there here in the put T we are going to use this keyer that we have generated so just provide your host name and that is the uh public address that we have copied the same thing you have to provide here in theost host name of puty and in the SSH authentication you have to provide the key pair that you have downloaded to connect with the ec2 instance so your E2 instance is created and it is running now with the help of puty we are going to connect with the ec2 instance and then do the necessary thing that is required so let me try to uh first let me try to provide the host name here so just go there and this is the host name and the it will ask you for the username as well okay so you have to provide the usern name when you're going to connect with the puty as well uh like you have to provide the host name apart from that it will also ask you the username so I'm going to provide the username here itself so the username would be ec2 hyphen user and then we are providing the host name so when we are going to provide this in the host it will take let me try to copy this out it will take uh EC to hyphen user as a user and then this is the host so both of the credentials we are going to provide here in the host itself so just paste it out and uh now go to this uh SSH go to this o and here you have to provide the key that you have downloaded from the key pair from the WS when we are going to when we are creating the ec2 instance so just browse it out and I have placed it somewhere in the AWS folder so let me try to go there in the new folder and try to open it out here and then just open it it will take few second you have to accept this and then it will take few second to connect with your ec2 instance so here you can see the ec2 hyphen user is the username and we have provided the host where this e this puty is being connected to the uh ec2 instance so you have to provide the username and the host name as well or you can say the public DNS in the host of puty and then you have to uh provide the key PS that you have downloaded now we we are inside the E2 instance okay now let me try to check uh if something like if the Java is there in your ec2 instance or not so because we are going to deploy our application and that application requires the Java 17 if you'll go to this uh intellig and in your application you will find that uh if you'll go to the pom.xml file if you'll go above you can see the Java version that is required for this project is 17 so let me try to check here in the ec2 instance if Java is there or not if it is not there we have to install the Java inside this ec2 instance so you can see uh when we are going to run the command Java hyphen iph version it is showing that Java command not found now what we have to do we have to install the Java inside this ec2 instance so I already have the command for that so let me try to run that you can see pseudo dnf install Java and we are going to install the Java Amazon not from the Oracle so let me try to install this here so let's say let me try to paste it out okay let me try to remove this so this is the command our Command is uh pseudo dnf install and then we have to provide the Java and the version of the Java that you want and then if you want to install the Java from the Oracle you can do that I'm going to download the Java from Amazon Corto so just try to hit enter and it will take few second you can see it is started installing the Java 17 and it is asking us uh to download the size of 100 MB and installed size would be 6 262 MB so just press y here and then it will take few second and download the Java for you so just wait for few second and it is stalling those things now I think it is installed let me try to cross check it and try to run the command again here you can see we are able to see the Java version which is uh open jdk runtime involvment Coro 17 so we have the Java here inside our ec2 instance installed okay now what we have to do is we have to move our jar file that we have created for this application to this ec2 instance so there comes the picture of wi SCP so now let me try to open the VP here and uh just wait for a few second it will up and what we have to do is we have to provide the host name here as well in the vinp so just let me try to provide the host name here so just we are not going to provide the user we are just going to provide the sorry yeah this is the host name we are just going to provide the host name so just copy this or public DNS you can see paste it out and then uh you have to provide the username here which is EC to hyphen user and in the password you have to provide the key payers that we have downloaded so go to this advance and uh go to this SSH authentication and private key files you have to upload here so just select this one and go to the desktop AWS AWS 24 new folder and select this key pair that we have downloaded now just uh okay and then log in it will take few second and just provide yes here it will connect with your ec2 instance so you can see on the right side we are in the E2 instance and on the left side we are on the uh like local files so you can see uh I have created this project let me try to go to the intellig and show you where this project is located so you can see this is the path of the project which is uh under YouTube engineering at the projector 2024 January and this is the project name which is AWS _ springbot _ demo so let me try to uh go to that location on the left hand side so we are inside the January and we have to select this project name which is springbot aw sorry AWS spring boore demo which is created today so just select this out and if you'll go inside the target of this you will find this J file which is AWS hyphen demo that we have created now select this jar file and right click on it and then do upload once you will try to do the upload it will upload your Jr file to the ec2 instance or you move your J file to the ec2 instance as of now if we go to this puty and if we'll try to do a LS here you won't find anything okay so you can see this is uh like this jar is being transferred it is not completely transferred so it is being sewing here before moving that or before uploading that jar to the ec2 instance if you'll come here and type the ls you won't see anything here but uh because it is being moved here you can see that is why we are able to see it inside the ec2 instance inside put T okay so you can see if you again run the command LS you will find that this jar is being moved here so now our jar is being moved here inside the ac2 instance now let me try to run the this jar okay so let me try to run this so there is a command Java minus jar and then provide the jar name which is AWS hyphen demo. jar so if you'll run this jar you will uh your application will be started and running okay so you can see our applic application being started and it is being started on the port number 8080 okay now with the help of uh the public DNS that is being provided by the cc2 over the CWS you can see this this is the public DNS right where it is okay if we go up you can see this is the one so with the help of this public DNS you can access your application now what is uh let me try to explain you the whole scenario what is being done here is we have created the E2 instance on AWS and with the help of putty we have connected with that ec2 instance inside that ec2 instance we were not having Java so we installed the Java inside that and with the help of V SCP we have moved our jar inside the E2 instance and now with we have all the things ready inside the E2 instance that run that can run our jar so we have the Java and we have the jar now we are running one command Java minus jar and we are providing the jar that we have deployed here in the E2 instance and our jar like our application is being started inside the E2 instance now with the help of uh the the address provided by the E2 instance we are going to access our application okay so let me try to go to this uh browser and let me try to provide the public address or you can say uh the public DNS that is being provided by the ac2 so just copy it and come here paste it out and then provide the API that you have developed so the API was for/ AWS you can see this now if we hit it just wait for a few second uh we are not going to see any result because we have to do one configuration so but yeah our API will be up and running on this location on this public DNS itself so just wait because it one configuration we have missed that is why we are not able to see the eror uh see the result here and we are getting this error you can see this now let me try to go to the instance and show you what is we have missed here so if you'll go to this network uh networking and if you'll go down okay let me try to go to the security and if you'll go down here you can see uh in the security rules inbound rules we have only one rule and it is allowing us on the port number 2 2 so we don't have the security uh for our application our application is up and up on the port number 8080 and that we have to configure here in our inbound rules so let me try to do that so just uh open this security groups and and go down and here you can see edit inbound rules just try to add a rule and let's say the type is custom TCP and you have to provide the port number on which your application is up and running so just uh provide that let's say 80 80 and where from where you want to access your apis from from where you want to access your application just provide this 0.0.0.0 for sl0 which is from anywhere so just select that and if you want to provide some description you can edit out now let me try to save this rules and if you'll go there to this API or to this URL and if you again hit it out you will see we will get the result here so just wait for a few second we are making one mistake here we are not providing the port number and that is why I think it is not working so this is the public DNS and this is the API but before that we have to provide the port number on which our API is up and running so this is the port number and then we have to provide the API so just hit it and then you can see we are able to see the result here which is uh we are able to see the response that we are getting from our API which is our first deployment on AWS E2 is successful and this is also we are getting here locally right so this is how you can deploy your spring boot application on AWS using E2 instance okay now uh let me try to go to the ec2 instance again and uh let me try to go to this ec2 and here you can see if you'll go to the instances you can see one instances and running okay so what we have to do is once uh let's say if you don't want to continue this uh what I would say application deployment you want to terminate or you want to stop your ec2 instance then you have to come here to the instances and go to the instance State and then just stop it if you're not going to stop it it is chargeable okay so like in the free tire in the free trial some uh amount of uh data is being given to you or some uh time limitation is there to use that E2 instance or to use any free T things okay so make sure that once the things are done if if you are doing this for the learning purpose make sure that once you deploy your application once the steps are clear to you try to stop this instances so that you can avoid the unnecessary charges put by the AWS so that is what we are going to do here our deployment is successful everything is working fine now how we can terminate our ec2 instance that is what we are going to see here so come here and try to I uh if you want to stop you can stop it out and directly you can come here and terminate as well so let me try to first stop it and then terminate it so it will take few second you can see it is started stopping and in few second it will be stopped once it is stopped what I will see uh what I will do I will try to terminate it and then after that we have to do some necessary cleaning on this instance so we'll do that and then we we are done okay so just wait for a few second you can see it is stopped now now let me try to come again here and try to if you want to start again you can start it out now if you want to permanently delete this instance you can come here to the terminate instance now let me try to terminate it and just you can see it is shutting down in few second it will be in the terminated State now make sure that whatever things are associated with this C2 instance you have to close it out you have to release it so if you'll come here you can see we have one key pairs we have one security groups and we have the one in instances so in the instance we have terminated it out it will take few minutes few hours it can take to reflect here as zero uh so don't worry on this make sure that you just going if you're not using this skip here so just select it out and try to delete it as well so come here and delete this so you have to type the delete here and it is deleted now again go to the instances and you can see the instance is in the terminated state but uh if you'll go to this easy to dashboard uh just refresh this out and here you will see the KPS is deleted now go to the security groups and uh you remember that we have created One Security Group so just delete that one uh there is one default one so don't uh delete that just select this which we have created and go to the Aon and try to delete security groups it is deleted now again go to the E2 dashboard and try to refresh this again and here in the security group it will be one so only the default one is there now if we'll go to the instances you can see your instance is terminated but still it is reflecting as one here so don't worry on it it will take few hours and then it will become zero so this is how you can delete your receipt to instance as well so this is about the video guys if you like the video please hit the like button and please subscribe the channel for more such content please share the videos with the friend in need and please support the channel thanks
Info
Channel: EnggAdda
Views: 510
Rating: undefined out of 5
Keywords: Spring Boot Development, Rest API Development, MySQL, Spring Boot, docker, dockerize, docker image, what is docker, docker definition, dockerhub, docker in spring boot, docker images, how to create docker image, docker basic, beginner to docker, spring boot and docker, docker hub, containers, docker containers, deamon, docker deamon, docker engine, aws, ec2, deployment, deploy spring boot app on aws, deploy using ec2, deploy your app on ec2, deploy on aws, spring boot aws
Id: tKG_OH4vJFg
Channel Id: undefined
Length: 32min 43sec (1963 seconds)
Published: Wed Mar 06 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.