How to Easily Deploy a Spring Boot Application to AWS EC2
Вставка
- Опубліковано 3 лип 2024
- The easiest way to deploy a Spring Boot application to the cloud is using AWS EC2. In this video I will show how to deploy a simple web application to EC2 in such a way it can be used from a CI/CD platform to upload a new version each time it's available.
This video belongs to a playlist where I show multiple ways to deploy application to AWS: • How to Easily Deploy a...
Content:
* What is the cloud. What are the main cloud providers
* What are the main services of AWS
* How does AWS EC2 work
* Which services are necessary to create an AWS EC2 instance. What is a Security Group. What is a VPC. What is S3.
* How to connect to an AWS EC2 instance in SSH
* How to create an AMI from a running AWS EC2 instance
* How to perform automatic actions on a AWS EC2 instance at the startup
My NEW eBook: sergiolema.dev/git-book/
Blog: bit.ly/47ornJL
LinkedIn: bit.ly/41Nn61q
Facebook: bit.ly/47rc9nh
My Desktop:
• Laptop: Macbook Pro 16' 2019
• Gaming Chair: amzn.to/47Vu6ed
• Mouse: amzn.to/3HoBwM1
• Desk: amzn.to/48Tc5Oi
• Screen: amzn.to/48VZkCL
Icons:
* credit cart by Larea from Noun Project
* comment by Gautam Arora from Noun Project
* Server by Alzam from Noun Project - Наука та технологія
Explanation is very clean. This video helped me a lot. Thanks🙏
Thank to you for watching! Don't forget to share my channel with your network
@@TheDevWorldbySergioLema Yeah, I'm sure my network will enjoy it 👍
Amazing video. All explained in just some minutes. Congrats!
Thank you Santi!
The fact that half-way through this video, I was able to get a simple Spring Boot application on an EC2 instance makes it golden. Thank you so much!
Thanks for the comment Anthony!
duuuude, U have no idea how much u helped me with this video, u re the best!
So glad Andrej!
Explanation very clean and excellent, thank you
Thanks Youness!
I try my best
Cool, looking forward to another one
Yes, I'm already working on it
Beautiful video, props bro!
Thanks Luka!
Thank you! Your video was very helpful for me
So glad. Don't hesitate to share it in your network
this tutorial is very helpful. thank you!
Thank you
Excellent video. Thank you so much.
Thank you Ernest!
Great video, thank you!
Thanks to you for watching!
Great video. Thank you
Thanks for watching! 😉
Great video.
Thanks Mike!
Thank you so much! This made so many things clear to me. I worked with several old ways to manage my projects. From hosting my own servers (about 20 years ago) to some docker managed instances and so on. AWS was a misterium for me. So many things you can do there but you brought it to the point for me. EC2 is only a virtual machine :) And the networking is also only networking VPC (virtual private cnetwork ;))
I'm so glad you understand it better now!
@@TheDevWorldbySergioLema I am looking the next video (4 Easy Steps to Deploy ...) and I left a similar comment there. Really, it's a kind of AHAAA moment for me. thank´s again!
Thanks again!
this video is helpful alot
Thanks!!
thanks, it helps a lot
So glad!
Inbound rules part is very helpfull.
Glad it helped you!
Thanks teacher
Keep watching more videos! 😉
Please continue make videos about Java and AWS
I'm on it 😉
Video on VPC and networking would be great
Ok, thanks for the feedback John
Thank you. All network services in AWS are very helpful. please if possible please give it to us. thank you.
I'll take it into account
nice bros
Thank you!
Thank youuuu for the amazing video !
Does anyone know from where i can get that ssh key before creating the instance?
You have to create it by your own, in your computer. Then upload it to AWS and assign it to the created EC2 instance.
Hi ,At 4.36 of the video you have used SSH keys , how to created that one please let us know .The one it shown is already created one you have imported.
You have many ways to generate ssh keys. It depends on your OS. On windows, you have OpenSSH or Putty. On Linux or MacOS, you have ssh-keygen.
Thanks for the video. While I am trying to start ec2 instance using public ip address from local terminal. Connection is failing. Even ping to public ip is not working. can you suggest what would be failing ?
Check your security group. I must at least accept the port 22 for SSH and port 80 for ping.
Hi! Your video is excellent and is helping me a lot during my final project at college. However, I can't run the command "mvn" on my terminal (command not found). I also have a maven spring boot project, but I don't get what I did wrong. Would you help me, please?
Thanks. The "mvn" command is the Maven command. If you don't have it installed in your EC2 image, you can also use the Maven Wrapper in many Spring Boot projects (which doesn't need to install).
I encountered problems (I'm using windows), you can also use EC2 console to connect
Yes, the AWS console is very useful, as you don't need to configure your computer
is aws ec2 from aws free tier?
when you import key pair, how did you get the content?
it's the public part of my SSH key. You can easily find how to generate SSH keys here: www.google.com/search?q=create+ssh+key
thanks, great content
Thanks for watching!
After creating an application in Elastic Beanstalk, an error appears "The instance profile aws-elasticbeanstalk-ec2-role associated with the environment does not exist." Why is this happening?
The video is not about Elastic Beanstalk. I haven't used Elastic Beanstalk for a while, I can't help you. Maybe if somebody else see the comment and knows the answer...
Sergio, video de VPC !!
Noté!
When I run the demo command in the terminal 08:00 , I get the following error:
" 'demo' is not recognized as an internal or external command,
operable program or batch file. "
What can I do for it? Can you help?
😂 Sorry, demo is the name of the folder where I run the commands. My terminal displays it in another colour. It displays first the folder where I'm running the commands.
how do i add environment variables
The best way is to add them when creating the EC2 image, or in the startup script.
Is it possible to do the same but with a war file instead of a jar file?
With a war file, you nees to first install a web server like Tomcat or Glassfish. The rest is the same (EC2 creation, security groups, VPN...)
Merci pour la vidéo Sergio. Tu crée une nouvelle instance EC2 pour le CI/CD, mais comment arrêter, effacer ton ancienne instance et transférer les requêtes vers la nouvelle vm pour ne pas utiliser trop de ressources lors du déploiement?
Merci pour ton commentaire Bruno. Là tu parles d'un cas plus avancé. En utilisant uniquement EC2, tu peux réussir ça en mettant un Load Balancer devant ton instance EC2. Quand tu crée ta nouvelle instance, il faudra la déclarer dans le Load Balancer. Et quand ru supprime l'ancienne, elle sera automatiquement supprimée du Load Balancer. Et le Load Balancer se chargera de rediriger le traffic d'une instance à l'autre.
The worst part is some things are already configured at tutors end, like console, terminal etc, and we are not sure how did tutor set them up in first place ;( . also, having lengthy commands pasted in description would make it easier for us to simple copy paste and do the job :)
Sorry for not copy-past the commands on the description, but UA-cam don't render well some commands as it thinks it's some Script injection attack.
The only thing I have previously configured, is the aws configure to create a profile connected to my AWS account. You can check how to do it here: docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-using-profiles
Can the REST API's be accessible outside the region of EC2 ? I mean are the REST API's global ?
It will depend on you Security Group, which Inbound traffic you authorize.
i wish if ur instructions were simpler on where did you run your startup code how to make ssh etc
Sorry, I assumed you already have some knowledge about bash scripting. Tell me your doubts, I may guide you with some resources or links.
If you get Permission denied (publickey,gssapi-keyex,gssapi-with-mic) when tring to ssh to ec2-user, just run chmod 400 on the pem file and try again
Great advice!
How do you do this on windows CMD?
The goal of those commands is to run them from a CI/CD platform like GitlabCI. I've never used Windows on a CI/CD platform.
But the AWS CLI is the same for Windows. You can check the installation guide in the official AWS Console page.
oh right so we should be using the AWS cli here not windows CMD prompt. I think a few people are confused as to what shell was used in this video to run the command ssh ec2-user@blablabla
what terminal did he open?
I use iTerm, but this won't change anything to the behavior.
Hi, I have connected to the server using ssh ec2-user@MY_IP
it was success, and I've installed java.
but when I tried to upload the JAR file I get this error:
ED25519 key fingerprint is SHA256:XXXXXXXXXXX.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
and when I click yes, I get this error:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
Connection closed
i was having the same error, make sure that you are running the scp command on your local machine and not while connected to the ec2 instance :)
You must use the same user ec2-user when copying the JAR file, "scp file.jar ec2-user@MY_IP:/home/ec2-user/"
I created the vpc, ssh key, security group, the instance, followed everything in the video, and when I went to my terminal and did ssh ec2-user@, I got the error: Permission denied (publickeymgssapi,keyex,gssapi-with-mic). Anybody else?
Did you linked your ssh key to the EC2 instance?
Exact same happened to me. Will rewatch the video in case I missed a step.
watched the video again and got stuck at the same part
I suppose which terminal should we be using? I think it might be the AWS cli? I'll try this now
Why can't access end points after closed the terminal?
In my case, I run the Spring Boot application in the terminal, not in a background task. If I close the terminal which is running the application, it stops.
For production ready applications, you should configure the startup of your application in the User Details script. This way, it's running as soon as the instance is up.
@@TheDevWorldbySergioLema Can you please share the details. How to do this?
It's the script I write into the UserDetails field in the video.
Is there a free aws for spring boot?
There are free Linux servers in AWS for one year. You can run whatever you want on them.
how did you add ssh key and what is ssh key, where to find that?
An SSH keys is like a username/password to let your computer connecter to another computer via the port 22.
You can generate them with ssh-keygen, putty or other tools.
You must first generate a public/private key in your computer, then upload in the Key Pairs section of AWS the public one. Then, you can connect to the EC2 instances which have your Key Pair.
@@TheDevWorldbySergioLema I have generated my key-pair, uploaded the public one to was and I still cannot connect. the error is `Permission denied (publickey,gssapi-keyex,gssapi-with-mic).`
Maybe your SSH key has permissions too open. Maybe the route to your SSH key is not the default one and your SSH agent can't find it. Check this link and try add the verbose option to see more details about the error: askubuntu.com/questions/311558/ssh-permission-denied-publickey
how to deploy database
I didn't made a video about that, because it's just going to RDS, select the database, select the instance type, the amount of memory, and that's all
How did you make the SSH key ?
With ssh-keygen. For you, it will depend on your OS: docs.oracle.com/en/cloud/cloud-at-customer/occ-get-started/generate-ssh-key-pair.html#GUID-8B9E7FCB-CEA3-4FB3-BF1A-FD3406A2432F
@@TheDevWorldbySergioLema thank you. As an alternative I can use the pem file too. Right ?
I'm not sure about this. I would say no, but I've never tried.
how to keep it running even after ssh session is terminated and my pc is shutdown? the app shuts down after a while
You can simply run it in background. Add the & symbol at the end of the command, and it will run in the background. Or create a screen and run it in the screen. Either way, when closing the SSH session, the application still runs.
@@TheDevWorldbySergioLema it still shuts down when i close the terminal i need to run like a dedicated server
I'm not sure about what you mean about '"close the terminal". When running the server, you must add the "&" symbol at the end of the command. Then, you should have the terminal free to continue. Exploring the processes, ps -a, you should see the previous server running. Then, close the SSH connection and the server must continue to run.
If the "&" symbol doesn't work, try using a screen (linuxize.com/post/how-to-use-linux-screen/).
@@TheDevWorldbySergioLema thanks a lot the screen worked like a charm
I use it every time a need a long running task in a distance server.
Sorry I'm dumb. When you say "and go to a terminal" (to connect to the instance). Do you mean just the command line on my local machine? Or are you talking about something in AWS? Doesn't AWS provide like 3 different ways within the console to connect to the instance? What do you mean when you say "and go to a terminal"?
tried it from the command line.... permission denied....
Go to your local machine terminal. But you need to configure it before. Check here how to do it: docs.aws.amazon.com/cli/v1/userguide/cli-chap-configure.html
@@TheDevWorldbySergioLema So I have made a lot of progress. Got a JAR file of my app onto the Linux Ec2. But when I run it, it doesn't pick up the properties from my properties file so I can't make the MYSQL DB connection. It keeps acting like it's trying to connect with root@... , But I have a ${DBUSERNAME} variable (and PW and URL) in my props file and I CANNOT get the app to pick those values up and connect with that. ANY ideas bro?
nube*
😅 Ups, corregido
those kind of tutorial create more confuse
I'm sorry for that.
What was not clear enough?