Spring Boot, Spring Cloud AWS and ElasticBeanstalk — Part 2 — Deployment
This is the second part of a two part blog series which was intended for demonstrating development of a web application which is eligible for deployment to AWS platform and utilizes some of AWS provided services like the RDS service.
If you missed the first part which was talking about development of a trivial application using Spring Boot and Spring Cloud AWS you can find it here. This part is going to be talking about AWS ElasticBeanstalk and how we can utilize it to deploy our application to AWS platform. As our application is backed by a MySQL database and we aim to use RDS service for a relational database I’ll also describe creation of a simple DB instance on RDS. So if everybody is ready let’s start!
What’s AWS ElasticBeanstalk?
AWS platform provides several services. Although AWS already provides tools for easily creating and configuring these services it can become tricky to wire them altogether once the number of the services increases. ElasticBeanstalk is another service provided by AWS which comes handy in these kind of situations. It overcomes the complexity by having you create and base-configure different AWS services depending on your needs with a few clicks. You can always fine tune the default configuration in the future.
In our case we’re going to use ElasticBeanstalk to wire EC2, S3 and RDS services which are going to be used for Tomcat App Server Instance, storage for server logs/configuration and our MySQL instance respectively.
Creating The RDS Instance
As our application is going to be backed by a MySQL (RDS) instance before proceeding with the application deployment we should get our RDS instance up and ready. To do this we should click on the RDS link on AWS Console Services menu.
This will lead you to the page displayed below. Just click on the “Get Started Now” button to start configuring your first RDS instance.
On the next screen select your DB Engine type and click “Select” button. As we are developing our sample applications backed by a MySQL instance we’ll be selecting the MySQL from the list.
On the next page you should select whether you want to use this RDS instance with production purposes or this is going to be a Test instance. In our case as we’re creating the instance with blog purposes and want to remain in the Free Usage Tier we’re selecting the Dev/Test option.
The next page is where you specify the database details. It’s ok to leave it with defaults for testing purposes. Just make sure you select the db.t2.micro instance as displayed on the below screenshot to stay safe on the free tier. Below the page there is the settings part. Please keep in mind that for your application to be able to connect to this RDS instance credentials you provide here should match with the ones at your @EnableRDSInstance annotation in your Application.java class. You can reference the first post here for details.
The last page is ok to be left as is with defaults. One thing to be aware is to complete the Database Name property displayed below unless you want to end up with an empty MySQL instance. Database Name should match with the one you provided in the Application.
Deploying The Application
At this point RDS (MySQL) configuration is completed. It’s time to start our application deployment via Elastic Beanstalk.
You can access the Elastic Beanstalk Console after you login to the AWS main console by clicking Elastic Beanstalk link displayed below.
On the welcome page first thing to do is to select the correct platform for running our sample application. As our application is Java Web Application, Tomcat is a good choice. By default a Tomcat 8 running on a Java 8 environment is provided which is suitable for our testing purposes.
Once you select Tomcat and click continue you’ll be forwarded to below page. At this point Elastic Beanstalk is configuring several services and wiring them together for your use for the first time. It will also be deploying a static web page on the Tomcat.
Once the “Health” status on the above page turns to Green from Grey, it’s time to deploy our application. Click the “Upload and Deploy” button in the middle of the page and below screen pops up. Just click the “Choose File” button and go and select the war file in the target directory of the application folder described in the first blog post. Don’t forget to select the Batch Size as fixed and instance count to 1 to stay on the Free Tier.
Once you see the below screen, your deployment is complete and you have a Rest based, MySQL backed java web application running on AWS. Yes, just that easy!