Deploy Simple Spring Boot CRUD App to AWS Elastic Beanstalk and Connect AWS Relational Database Service(RDS)
Simple Deployment Example of Spring Boot CRUD Application to AWS Elastic Beanstalk and Connection example of AWS RDS
This is a Beginner Level Tutorial about How to deploy a Spring Boot CRUD Application on AWS Elastic Beanstalk and Connect to AWS Relational Database Service (RDS). I created a simple Todos application with Spring Boot. I am going to use Postman to emulate CRUD operations.
You can download the application source code.
👈What This Post is NOT About👉
- Not an advanced AWS tutorial
- Not an Elastic Beanstalk tutorial
- Not a Spring Boot CRUD web application tutorial
👉What This Post is About👈
- To show how you can deploy an application to Elastic Beanstalk.
- To show how you can connect AWS RDS
- To show how you can check logs for simple errors.
- Spring Boot knowledge
- Jar creation knowledge
- Basic AWS knowledge
1- Download Source Code of CRUD Spring Boot Application
2- Create A Database on Local MySql
3- Connect Spring Boot to Local MySql DB
4- Test Local Endpoint with Postman
5- Create a MySql Database on AWS
6- Configure AWS RDS for Local Connection
7- Configure Local to Connect AWS RDS
8- Create and Configure an Elastic Beanstalk Application
9- Deploy Spring Boot Application to AWS Elastic Beanstalk
10- Check Logs for Error
11- Test Deployed Application
Download Source Code of CRUD Spring Boot Application
I created a very simple Spring Boot todo application which we will use in this post. We are going to use Postman to emulate front-end actions. You can download the source code via this link.
Create A Database on Local MySql
I am going to create a local database to test before deploying my application to AWS. I am using PhpMyAdmin as GUI. You can use GUI or terminal.
DB Name => aws_crud_demo
User Name => root
Password => password
We are going to use the above information to configure the spring application.
Connect Spring Boot to Local MySql DB
We need to add a couple of dependencies to connect MySql.
Finally, we need to add the following properties to the application.properties file.
Test Local Endpoint with Postman
All CRUD operations are working.
Create a MySql Database on AWS
First, find the RDS service on the AWS console.
There will be a configuration page. So I am going to show you my configurations.
Choose MySql as an Engine option. I also choose
Dev/Test environment for minimum resource usage.
We have to name our DB instance. Don't forget it is not the name of the Database, it is the name of the DB instance. I give the same username and password as Local for convenience.
I give 20GiB volume, you can give more it is up to you.
We want to connect this DB from our local too. Therefore we need to open it for
public access (NOT PRODUCTION RECOMMENDED).
Now it is time to create the Database.
AWS gives an estimated monthly cost.
instance creation takes a while.
If you click instance name, you could find the URL of Database
Configure AWS RDS for Local Connection
As I said, we want to connect this DB instance from our local. Therefore, some additional configuration is needed.
If You click the DB instance, AWS will take you to the details page.
There is a security part on the detail page. When you click it, it will take you
Security Groups and when you click security groups, it will take you
inbound rules which we need.
We are going to add a new rule for Local connection. As you notice, it is only for the sake of this tutorial, I do not recommend this kind of rule.
Rule successfully added.
Configure Local to Connect AWS RDS
It is very simple actually. Just replace local URL with AWS RDS URL on application properties. I comment out the old one and added the new one.
It is connected and I check all CRUD operations are working.
Create and Configure an Elastic Beanstalk Application
Choose Elastic Beanstalk service from the console.
There will be a welcoming page. Choose
We will configure Elastic Beanstalk
we are going to connect our already created AWS RDS instance to the application.
Fill in the required fields and save.
save all configurations.
Application creation takes a while.
Deploy Spring Boot Application to AWS Elastic Beanstalk
After creation completed, the application page will be opened. There is an Upload and deploy button. We are going to upload our application's Jar file.
Upload finished AWS deploys our application.
Application deployed, there is a URL that we can use for CRUD operations.
But it is not working.
Check Logs for Error
There is a
Logs a menu item at the left sidebar on the same page.
It let you download all logs related to the application.
And When I examine it, notice that it is a port error. Our application listens
8080 but Nginx listens
There are 2 solutions.
- Change application port on
application.propertiesfile. Rebuild application and upload jar.
2. There is
configurationon the left sidebar. It can take you to software configurations and you can add a new
environment variable .
Test Deployed Application
Now, It is working
Everythings are working.
Deploying a Spring Boot Application on AWS Using AWS Elastic Beanstalk | Amazon Web Services
In this blog post, I will show you how to deploy a sample Spring Boot application using AWS Elastic Beanstalk and how…