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
-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.
 Creating CodePipeline
(1) In Management Console, search for CodePipeline and click it.
(2) Click “Create pipeline”.
(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.
(4) Next is the “Add Source Stage” screen. Enter/select as follows and click “Next” (⑤)
|①||Source Provider||AWS CodeCommit|
|②||Repository name||Step 2: Create repository name of Git repository|
|④||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).
(6) The “Create Build” window will appear. Enter/configure as follows and click “Proceed to CodePipeline”.
|①||Project name||Arbitrary name (this time “sample-eb-java-build”)|
|②||Environmental image||Managed image|
|③||Operating system||Amazon Linux 2|
|⑥||Image version||Select latest|
|⑧||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
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/121579f0-93f9-63e4-5bf0-dbc26a437db2.png) (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" ( ②). ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/df21d5df-3c7e-aad7-be0e-25fe8985b9aa.png) (7) After transitioning to the "Deploy-Optional" screen, enter/select as follows and click "Next" (⑤). |No|Name|Settings| |---|---|---| | ① | 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" | ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/4af2e9fd-1ffa-2cb3-219a-941dbc772b45.png) (8) After transitioning to the "Review" screen, confirm the contents and click "Create pipeline". ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/53e41259-016e-06a9-c701-2c4df6cd5ad3.png) (9) The pipeline is created, and the commit/pushed code is built and deployed in order in “2. Creating a Git repository”. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/0576bee0-0585-8e5b-731b-bc1be1e47240.png) (10) If the deployment is successful (with a green check mark), OK. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/d3451d71-5823-fa1c-432a-d17e781af7e3.png) 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". ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/fbbf39b2-38e1-8751-df16-5882d1c9139b.png) (12) Click "Environment" in the navigation pane. ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/ba201534-33cd-e82f-80d5-fec2eb230d01.png) (13) If your health is "OK" as shown below, you are successful! (①) ![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/356958/936d2cdd-8546-9448-bceb-2da5def6431a.png) ####  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 ```
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.
 Elastic Beanstalk
(1) Click “Services” (1)> “Elastic Beanstalk” in the Management Console.
(2) Click “Environment” in the navigation pane.
(3) Select the radio button of the target environment (1) and click “Action”> “End environment”.
(4) Move to the “Confirm Delete Environment” screen. Enter the name of the environment (1) and click “Delete” (②).
(5) Then, delete the “application”. Click Application in the Elastic Beanstalk navigation pane.
(6) Select the radio button of the target application (1) and click “Action”> “Delete Application”.
(7) The modal “Confirm application deletion” will be launched. Enter the target application name (1) and click “Delete” (2).
(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”.
(2) Select the radio button of the target pipeline (①) and click “Delete Pipeline” (②).
(3) Since a modal confirmation of deletion is launched, enter “delete” (1) and click “Delete” (2)
At the end
Thank you for your hard work for a long time.
I am confused by the gradlew of 1--(5) change for 3 days, and at the deployment stage of 5--(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/)