A story that stumbled when deploying a web application created with Spring Boot to EC2

Introduction

This is a memo for myself.

Development environment

・ Windows 10 ・ OpenJDK 1.8 ・ SpringBoot 2.2.4 ・ Gradle 6.3 ・ MySQL5.7 ・ AWS (EC2 ・ RDS ・ VPC)

Workflow

  1. Prepare Spring Boot app for deployment
  2. Prepare EC2 / RDS / VPC
  3. Install the required tools on Amazon Linux 2
  4. Build and deploy

1. Prepare a Spring Boot app for deployment

This can be anything, so you can use your own app

2. Preparation of AWS (EC2 / RDS / VPC)

I will post this later

3. 3. Install required tools on Amazon Linux 2

Log in to EC2 and update yum

# yum update

Check and install Git version

# yum search git
# yum install git

Check once Git is installed

# git --version

Install Java 8

# yum install -y java-1.8.0-openjdk-devel

Install and relocate tomcat For more information here

Clone git

# git clone https://github.com/sample.git

Move to the cloned directory and spread gradlew permissions

# chmod 755 gradlew

I want to build as it is, but move to application.properties and change the settings application.properties is an environment-dependent relationship

# cd src/main/resources
# vim application.properties

I think the URL of MySQL is localhost, so change here

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://"Localhost" ← here!:3306/sample?serverTimezone=JST
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.initialization-mode=always

Change localhost part to RDS endpoint

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://~~~~~~~~~~:3306/sample?serverTimezone=JST
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.initialization-mode=always

I changed it so that I can connect to RDS. We will build from here! !!

# ./gradlew build

Move to under libs of build as soon as build is completed I think there is an application that I built, so loosen the permissions Change owner and group to tomcat

# chmod 755 sample.war
# chown tomcat:tomcat sample.war

Then move it under webapps and start tomcat

# mv sample.war /opt/apache-tomcat/webapps
# systemctl start tomcat.service

If you connect to the URL set by EC2 ...

that's all

Recommended Posts

A story that stumbled when deploying a web application created with Spring Boot to EC2
I tried to clone a web application full of bugs with Spring Boot
What I was addicted to when developing a Spring Boot application with VS Code
A memo that I was addicted to when making batch processing with Spring Boot
When introducing JOOQ to Spring boot, a story that was dealt with because an error occurred around Liquibase
Four things Heroku stumbled upon when deploying a web app created in Java with GitHub
Let's make a book management web application with Spring Boot part1
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
Story when moving from Spring Boot 1.5 to 2.1
Run WEB application with Spring Boot + Thymeleaf
A story that made me regret when a "NotReadablePropertyException" occurred during the development of the Spring Boot application.
Java beginner tried to make a simple web application using Spring Boot
Introduction to Java development environment & Spring Boot application created with VS Code
Create a web api server with spring boot
[Spring Boot] Precautions when developing a web application with Spring Boot and placing war on an independent Tomcat server
Sign in to a Spring Boot web application on the Microsoft ID platform
From creating a Spring Boot project to running an application with VS Code
A memorandum when creating a REST service with Spring Boot
A site that was easy to understand when I was a beginner when I started learning Spring Boot
A story that failed when connecting to CloudSQL by running Sprint-boot with kubernetes (GKE)
[Spring Boot] Web application creation
The first WEB application with Spring Boot-Making a Pomodoro timer-
Deploy the application created by Spring Boot to Heroku (public) ②
Sample web application that handles multiple databases in Spring Boot 1.5
Deploy the application created by Spring Boot to Heroku (public) ①
Spring Boot application that specifies DB connection settings with parameters
Implement a simple Web REST API server with Spring Boot + MySQL
A story that I struggled to challenge a competition professional with Java
Minimal configuration to run Spring Boot application on Azure Web Apps
Inquiry application creation with Spring Boot
Build a web application with Javalin
Sample code to unit test a Spring Boot controller with MockMvc
A story that struggled with the introduction of Web Apple Pay
Create a Spring Boot web app that uses IBM Cloudant and deploy it to Cloud Foundry
Spring Boot2 Web application development with Visual Studio Code SQL Server connection
A story about a Spring Boot project written in Java that supports Kotlin
[Android] A story that stumbled when introducing ZXing, a QR code function library
I tried to make a Web API that connects to DB with Quarkus
Spring Boot2 Web application development with Visual Studio Code Hello World creation
Automatically deploy a web application developed in Java using Jenkins [Spring Boot application]
Deploy the WEB application by Spring Boot to Tomcat server as WAR
[Java] Deploy a web application created with Eclipse + Maven + Ontology on Heroku
How to migrate a web application created in a local docker environment to AWS
I want to develop a web application!
Processing at application startup with Spring Boot
Web application scheduled to be created (editing)
Launch Nginx + Spring Boot application with docker-compose
Changes when migrating from Spring Boot 2.0 to Spring Boot 2.2
[AWS] How to automatically deploy a Web application created with Rails 6 to ECR / ECS using CircleCI ① Preparation [Container deployment]
How to deploy a system created with Java (Wicket-Spring boot) to an on-campus server
A story that I was really into when I did triple DES with ruby
Create a website with Spring Boot + Gradle (jdk1.8.x)
Configure Spring Boot application with maven multi module
Create a simple search app with Spring Boot
How to use MyBatis2 (iBatis) with Spring Boot 1.4 (Spring 4)
I want to read the property file with a file name other than application.yml or application- [profile name] .yml with Spring Boot.
A story that took time to establish a connection
Create a Spring Boot application using IntelliJ IDEA
Try to implement login function with Spring Boot
Try to automate migration with Spring Boot Flyway