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

👋Introduction

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.

👈What This Post is NOT About👉

  1. Not an advanced AWS tutorial
  2. Not an Elastic Beanstalk tutorial
  3. Not a Spring Boot CRUD web application tutorial

👉What This Post is About👈

  1. To show how you can deploy an application to Elastic Beanstalk.
  2. To show how you can connect AWS RDS
  3. To show how you can check logs for simple errors.

🚨Prerequisites

  1. Spring Boot knowledge
  2. Jar creation knowledge
  3. Basic AWS knowledge

📖 TLTR;

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
12- Resources

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

Connect Spring Boot to Local MySql DB

We need to add a couple of dependencies to connect MySql.

<dependency>
<
groupId>org.springframework.boot</groupId>
<
artifactId>spring-boot-starter-data-jpa</artifactId>
</
dependency>
<
dependency>
<
groupId>mysql</groupId>
<
artifactId>mysql-connector-java</artifactId>
<
scope>runtime</scope>
</
dependency>
spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/aws_crud_demo
spring.datasource.username=root
spring.datasource.password=password

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.

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.

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.

#spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/aws_crud_demospring.datasource.url=jdbc:mysql://aws-demo-instance.cluuww5tunoz.eu-north-1.rds.amazonaws.com:3306/aws_crud_demo

Create and Configure an Elastic Beanstalk Application

Choose Elastic Beanstalk service from the console.

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.

Check Logs for Error

There is a Logs a menu item at the left sidebar on the same page.

Test Deployed Application

Now, It is working

Junior Full-Stack Developer

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store