I am working on a full-stack application [Spring Boot (Java), AngularJS 7, MySQL] and Apache Maven as a build tool => I need to deploy and host this web app on AWS. I searched about it and find out I have to use PAAS. There are 2 things. 1- AWS Elastic Beanstalk 2- Amazon EC2 my question is that what services should I use to deploy and host my web app.
Technically, these and many others would work. In fact, Elastic Beanstalk uses EC2. EC2 is just the service that provisions the machines where code can run. Elastic Beanstalk is basically a layer on top of that, that hides some of the EC2 complexities.
But complexity is a key thing to consider here. There is a lot of configuration that goes into setting up a deploy environment that is secure and stable. Unless you're an infrastructure expert, I would leave a direct EC2 setup alone.
If you, as a developer, have to set up a deployed app with no infrastructure team to support you, I would opt for something that does the most abstracting away of the complexities: So either Elastic Beanstalk or something like Heroku. I personally use Heroku for my personal projects, because of its ease of use.
Here is my recommendation...and I do this sort of thing all the time.
Create a VPC with public and private networks. Launch a t3.small instance with Amazon Linux and install Jenkins in your public subnet of the network. Make sure all your Java dependencies are there...which they should be. If not, install them.
Create your Elastic Beanstalk application with Spring Boot, Java and Maven...which should be the Corretto 11 running on 64bit Amazon Linux 2/3.2.8 (as of today). You will need to have a file named Procfile
in the root of your project. This will initiate your app start up. It should contain something like:
web: java -Dserver.port=8084 -jar build/libs/myapp-*.jar
(relative to the root of the project)
In Jenkins you will make a project for building your Java application. In the project, you simply add the instructions in a shell script exactly like you would do it from the linux command line. You can also find Maven plugins. It's up to you and you can figure out how best to do that.
Your EB App and Environment should deploy the load balancer in the public subnet. Your Java application should deploy in the private network. These are all part of the EB configuration. You will need to create a security group that allows port access from your load balancer to your application. Also, you should create a certificate in Certificate Manager for your domain, which should be setup in Route53. In EB, you can then configure your load balancer to always use that cert.
Your Angular application should be built in its own project on Jenkins. Then you should deploy it to S3 with Cloudfront as CDN in front of the S3 bucket. After each deployment, you should sync to S3 deleting all previous contents of the bucket. You also need to invalidate the cache for your Cloudfront distribution. This ensures your application is fresh and has all your updates and changes each deployment. You should apply your DNS routing to your Cloudfront distribution as well via Route53. There's documentation on doing all this.
To allow Jenkins to deploy to Elastic Beanstalk as well as S3 (and also perform Cloudfront invalidations on publish), simple create a Role in IAM that allows the permissions to the services you need. Once you have that Role, you should apply it to your EC2 instance that is running Jenkins.
Finally, your MySQL database should be in RDS. If production, use Multi-AZ, otherwise just launch what you need. Your DB should also be launched in your private subnet. You will need to create another security group for the DB as well. The DB security group should allow access from your application security group to your DB security group on port 3306 or whatever port you run on.
In Jenkins you will need to install any plugins you need for your git repository (bibucket, github, etc). In your repository settings, enable a webhook to your Jenkins server in the settings. The URL should be something like https://build.mysite.com/bitbucket-hook/
. Your projects should be separate for the Java app, build, and deploy. Similarly, your Angular app, build, and deploy. Each project should be in a separate repo with its own webhook. Separating your app, from your DB, and your frontend is best practice. It allows you to have room to scale each component independently and also decouples everything...API first concept. It also forces best practice security setup...Zero Trust concept.
So there are some specific suggestions. The nuts and bolts though are: MySQL in RDS. Java on Elastic Beanstalk, and your Angular application in S3 with a Cloudfront Distribution in front. Use Certificate Manager for your SSL and Route 53 for all your DNS. Figure all that out and you will have an industry stand stack that is ready for performance and scale.
It's true what others have said. Elastic Beanstalk is simply EC2, Application Load Balancer, Security Groups and a few other AWS services. You will see all your instances, security groups, load balancers, etc...where you'd expect them to be. However it makes it all turnkey...Cloudwatch, redundancy, scaling, deployment strategy, and subnet placement. EB has some idiosyncrasies, but building what it does on your own is much more work. If you want to get deeper into customizing your instances and web servers...research .ebextensions
and .platform
which you can drop in your project source and it will launch your stacks EXACTLY like you want them. Hopefully your setup is straightforward though and you won't need much of that.
Good luck!