[JAVA] Deploy a Spring Boot application on Elastic Beanstalk

Let's take a quick look at the steps to deploy a Java application using Spring Boot on Elastic Beanstalk (PaaS on AWS). Since this is the first post, I think there may be some areas that cannot be reached, but please understand.

You can deploy to Beanstalk from the AWS console, but this time I also want to execute it from the CI tool, so I will use CLI (EB CLI).

Premise

This time, I will explain the setting procedure of Beanstalk. I will omit the creation of the Spring Boot app. The build tool is gradle.

environment

Mac OSX10.14.3

EB CLI installation

Install the Beanstalk CLI with homebrew.

$ brew install awsebcli

AWS CLI installation

Also install the AWS CLI to save your Access Key and Secret Access Key settings.

$ brew install awscli

Access key setting

$ aws configure
AWS Access Key ID [None]: {Enter the access key}
AWS Secret Access Key [None]: {Enter the secret access key}

Project settings

Deploy in the project directory.

Example


$ cd workspace/ebdemo/demo

First is the project settings.

$ eb init

We will set it interactively.

region


Select a default region
1) us-east-1 : US East (N. Virginia)
2) us-west-1 : US West (N. California)
3) us-west-2 : US West (Oregon)
4) eu-west-1 : EU (Ireland)
5) eu-central-1 : EU (Frankfurt)
6) ap-south-1 : Asia Pacific (Mumbai)
7) ap-southeast-1 : Asia Pacific (Singapore)
8) ap-southeast-2 : Asia Pacific (Sydney)
9) ap-northeast-1 : Asia Pacific (Tokyo)
10) ap-northeast-2 : Asia Pacific (Seoul)
11) sa-east-1 : South America (Sao Paulo)
12) cn-north-1 : China (Beijing)
13) cn-northwest-1 : China (Ningxia)
14) us-east-2 : US East (Ohio)
15) ca-central-1 : Canada (Central)
16) eu-west-2 : EU (London)
17) eu-west-3 : EU (Paris)
18) eu-north-1 : EU (Stockholm)
(default is 3): 9

application


Select an application to use
1) [ Create new Application ]
(default is 1):

Enter Application Name
(default is "demo"):
Application demo has been created.

Platform → Java for Spring Boot


Select a platform.
1) Node.js
2) PHP
3) Python
4) Ruby
5) Tomcat
6) IIS
7) Docker
8) Multi-container Docker
9) GlassFish
10) Go
11) Java
12) Packer
(default is 1): 11

Select a platform version.
1) Java 8
2) Java 7
(default is 1):

SSH


Cannot setup CodeCommit because there is no Source Control setup, continuing with initialization
Do you want to set up SSH for your instances?
(Y/n): Y

Select a keypair.
1) key
2) [ Create new KeyPair ]
(default is 2): 2

Deploy

Copy the application jar to the project root before deploying.

$ cp build/libs/demo-0.0.1-SNAPSHOT.jar .

Deploy.

$ eb create
Enter Environment Name
(default is demo-dev):
Enter DNS CNAME prefix
(default is demo-dev):

Select a load balancer type
1) classic
2) application
3) network
(default is 2):

It will take a few minutes.

Operation check

It's working.

$ curl http://demo-dev.ap-northeast-1.elasticbeanstalk.com
Hello, World!

Second and subsequent deployments

From the second time onward, you can deploy with just the following command. If you set SSH, access key, etc., you can automatically deploy from CI tools.

$ gradle clean build test
$ cp build/libs/demo-0.0.1-SNAPSHOT.jar .
$ eb deploy

Postscript

It seems that the following settings are required in application.properties.

server.port=5000

Recommended Posts

Deploy a Spring Boot application on Elastic Beanstalk
Elastic Beanstalk (Java) + Spring Boot + https
Deploy to Ruby on Rails Elastic beanstalk (EB deploy)
Create a Spring Boot application using IntelliJ IDEA
Automatically deploy a web application developed in Java using Jenkins [Spring Boot application]
Spring Boot 2.3 Application Availability
Sign in to a Spring Boot web application on the Microsoft ID platform
Deploy to Ruby on Rails Elastic beanstalk (Environment construction)
Deploy the Spring Boot project to Tomcat on XAMPP
Spring Boot on Microsoft Azure
[Spring Boot] Web application creation
CICS-Run Java application-(4) Spring Boot application
Try Spring Boot on Mac
Deploy to Ruby on Rails Elastic beanstalk (IAM permission change)
[Java] Deploy the Spring Boot application to Azure App Service
Deploy the application created by Spring Boot to Heroku (public) ②
Deploy the application created by Spring Boot to Heroku (public) ①
How to deploy a Rails application on AWS (article summary)
Deploy a Docker application with Greengrass
Spring Boot application development in Eclipse
Spring Boot application code review points
gRPC on Spring Boot with grpc-spring-boot-starter
Hot deploy with Spring Boot development
Inquiry application creation with Spring Boot
Deploy a war file on Heroku
Implement Spring Boot application in Gradle
Try running Spring Boot on Kubernetes
A memo that touched Spring Boot
Let's make a book management web application with Spring Boot part1
Minimal configuration to run Spring Boot application on Azure Web Apps
Let's make a book management web application with Spring Boot part3
Let's make a book management web application with Spring Boot part2
Processing at application startup with Spring Boot
Create Spring Boot development environment on Vagrant
What is a Spring Boot .original file?
Spring Boot environment construction memo on mac
[Spring Boot] Precautions when developing a web application with Spring Boot and placing war on an independent Tomcat server
Java beginner tried to make a simple web application using Spring Boot
Start web application development with Spring Boot
Deploy a Java web app on Heroku
[Java] Deploy a web application created with Eclipse + Maven + Ontology on Heroku
Deploy a Tomcat-based Eclipse project on Heroku
Run WEB application with Spring Boot + Thymeleaf
I tried to clone a web application full of bugs with Spring Boot
From creating a Spring Boot project to running an application with VS Code
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 deploy a container on AWS Lambda
Run a Spring Boot project in VS Code
How to add a classpath in Spring Boot
Create a web api server with spring boot
Create a Spring Boot development environment with docker
What I was addicted to when developing a Spring Boot application with VS Code
Challenge Spring Boot
Spring Boot Form
Spring Boot Memorandum
A story that stumbled when deploying a web application created with Spring Boot to EC2
gae + spring boot
Spring Boot application built-in Tomcat, Apache and WebSocket integration
[Introduction] Try to create a Ruby on Rails application