[Java] [CodePipeline x Elastic Beanstalk] CI/CD Java application to Elastic Beanstalk with CodePipeline Part 3

4 minute read

It is a hands-on to CI/CD a Java application (obtaining a value from a database and returning the result in JSON format) to Elastic Beanstalk with CodePipeline. [CodePipeline x Elastic Beanstalk] CI/CD of Java application to Elastic Beanstalk with CodePipeline Part 2 Is the continuation of.


  • OS: Windows10
  • IDE: Eclipse 2020-03
  • JDK: Amazon Correto 8
  • Framework: Spring Boot
  • AWS -CodePipeline -CodeCommit -CodeBuild -CodeDeploy -Elastic Beantalk -Java SE (Java 8 version 2.10.8)
    → You can do the same procedure on different platform branches (Corretto 11 etc.). -RDS: MySQL Community Edition (Version 8.0.17)


5. Creating a pipeline

Finally the final stage. Create a CodePipeline and deploy it to your Elastic Beanstalk environment.

[1] Creating CodePipeline

(1) In Management Console, search for CodePipeline and click it. image.png

(2) Click “Create pipeline”. image.png

(3) After moving to the “Select pipeline settings” screen, enter the “pipeline name” (1), select “new service role” (2: default), and click “Next” ( ③). As a result, the role described in “Role name” is created when the pipeline is created. image.png

(4) Next is the “Add Source Stage” screen. Enter/select as follows and click “Next” (⑤)

No Name Settings
Source Provider AWS CodeCommit
Repository name Step 2: Create repository name of Git repository
Branch name master
Change detection options Amazon CloudWatch Events (recommended)


(5) Next is the “Add Build Stage” screen. In “Build provider”, select “AWS CodeBuild” (1), select “Asia Pacific (Tokyo)” for “Region” (2), and click “Create Project” (3). image.png

(6) The “Create Build” window will appear. Enter/configure as follows and click “Proceed to CodePipeline”.

No Name Settings
Project name Arbitrary name (this time “sample-eb-java-build”)
Environmental image Managed image
Operating system Amazon Linux 2
Runtime Standard
Image aws/codebuild/amazonlinux2-x86_64-standard:3.0
Image version Select latest
Environment type Linux
Service Role New Service Role
Role name Automatically entered (change if necessary)
Build specification Insert build command
Build command Input as *
Input mode Editor (capture is in edit mode by clicking “Switch to editor”)

```yml: * Contents of build command version: 0.2

phases: install: runtime-versions: java: corretto8 build: commands: -./gradlew test


(6) When you return to the "Add Build Stage" screen, confirm that "<Project name> has been created successfully by CodeBuild." is displayed (1), and then click "Next" ( ②).

(7) After transitioning to the "Deploy-Optional" screen, enter/select as follows and click "Next" (⑤).

| ① | Deployment Provider | AWS Elastic Beanstalk|
| ② | Region | Asia Pacific (②) |
| ③ | Application name | Application created in "3. Creating an Elastic Beanstalk environment" |
| ④ | Environment name | Environment created in "3. Creating an Elastic Beanstalk environment" |


(8) After transitioning to the "Review" screen, confirm the contents and click "Create pipeline".

(9) The pipeline is created, and the commit/pushed code is built and deployed in order in “2. Creating a Git repository”.

(10) If the deployment is successful (with a green check mark), OK.

From now on, every time a change is made to the CodeCommit repository's master branch, this pipeline runs.
In a real environment, it would be executed when pull request → merge from child branch.

If an error occurs during pipeline execution,
[[CodePipeline×Elastic Beanstalk] Error of CI/CD of Java application to Elastic Beanstalk with CodePipeline and its corresponding method summary](https://qiita.com/C_HERO/items/e3c98375d1a659920320)
Please try to solve by referring to.

(11) Let's check Elastic Beanstalk.
On the management console, click "Services" (1)> "Elastic Beanstalk".

(12) Click "Environment" in the navigation pane.

(13) If your health is "OK" as shown below, you are successful! (①)

#### [2] Operation check
(1) Let's check the operation.
In the browser, enter & enter as follows, and if the following result is returned, it is successful!

#### **` Execution URL`**

Domain listed in ② of (2) /shop-information/1 ``` image.png

6. Clean up

Finally, clean up. If you leave it as it is, you will be charged only for the operation of EC2 instance and RDS instance created in the creation of Elastic Beanstalk environment, so let’s clean up (delete) afterwards.

[1] Elastic Beanstalk

(1) Click “Services” (1)> “Elastic Beanstalk” in the Management Console.image.png

(2) Click “Environment” in the navigation pane. image.png

(3) Select the radio button of the target environment (1) and click “Action”> “End environment”. image.png

(4) Move to the “Confirm Delete Environment” screen. Enter the name of the environment (1) and click “Delete” (②). image.png

(5) Then, delete the “application”. Click Application in the Elastic Beanstalk navigation pane. image.png

(6) Select the radio button of the target application (1) and click “Action”> “Delete Application”. image.png

(7) The modal “Confirm application deletion” will be launched. Enter the target application name (1) and click “Delete” (2). image.png

[2] CodePipeline

(1) Next, CodePipeline. At least, if you do not change the code, there will be no charge, but conversely, if there is a change in some time, there will be a charge, so delete it as well.

On the management console, click “Services” (1)> “Code Pipeline”. image.png

(2) Select the radio button of the target pipeline (①) and click “Delete Pipeline” (②). image.png

(3) Since a modal confirmation of deletion is launched, enter “delete” (1) and click “Delete” (2) image.png

At the end

Thank you for your hard work for a long time.

I am confused by the gradlew of 1-[3]-(5) change for 3 days, and at the deployment stage of 5-[1]-(10) I stumbled 3 times with an error. became. However, the feeling of accomplishment when I was able to do it was unbelievable! !! I hope that it will be useful to as many people as possible, and I have summarized it in an article.

I would appreciate it if you could comment on any points that you did not reach or noticed.


5. Creating the pipeline

  • [Tutorial: Creating a simple pipeline (CodeCommit repository) aws](https://docs.aws.amazon.com/ja_jp/codepipeline/latest/userguide/tutorials-simple-codecommit.html)

6. Clean up

  • [AWS Elastic Beanstalk Price aws](https://aws.amazon.com/jp/elasticbeanstalk/pricing/)
  • [AWS CodePipeline Price aws](https://aws.amazon.com/jp/codepipeline/pricing/)