[Java] [CodePipeline x Elastic Beanstalk] Update the runtime version from Java 8 to Corretto 11 on the Java SE platform

12 minute read

On June 3, 2020, Elastic Beanstalk’s Java SE platform became generally available on the Corretto 11 (Java 11) platform branch.

  • LTS (Long Term Support) version is JDK11
  • Amazon Corretto has the shortest support period for Corretto 8 until June 2023, while Corretto 11 has a longest support until August 2024.

From that point of view, it is around the time that we want to support the update of the runtime version as soon as possible.

So, this time, I summarized the procedure to upgrade the Elastic Beanstalk Java SE environment from Java 8 (which is not Corretto 8) to Corretto 11.

Environment

  • OS: Windows10
  • IDE: Eclipse 2020-03
  • JDK: Amazon Correto 8 → Amazon Correto 11
  • Framework: Spring Boot
  • AWS -CodePipeline -CodeCommit -CodeBuild -CodeDeploy -Elastic Beantalk -Java SE: Java 8 version 2.10.8 → Corretto 11 version 3.0.3 -RDS: MySQL Community Edition (Version 8.0.17)

Assumptions

This article is [CodePipeline x Elastic Beanstalk] CI/CD Java application to Elastic Beanstalk with CodePipeline Part 3 | Qiita It will be the sequel position of (The cleaning up in step 6 will not be performed).

It is assumed that the environment of Java 8 version 2.10.8 platform has already been created & some of the similar contents are omitted. Please note.

Procedure

1. Update JDK from Amazon Corretto 8 to Amazon Corretto 11

First, in the local environment, the JDK is upgraded from Amazon Corretto 8 to Amazon Corretto 11 to check the operation and eliminate the error.

[1] Preparation

(1) First, let’s clean the target project with Amazon Corretto 8 applied. Click “Project” (1)> “Clean” (2) on the menu bar. image.png

(2) Check the target project (①) and click “Clean” (②). image.png

(3) After cleaning is completed, check the following items.

  • ① There are no errors
  • ② The application starts up and operates normally.

Please check.

① You can check the error on the “Problems” tab (④) that appears when you click “Window” (①)> “Show View” (②)> “Problems” (③) on the menu bar. image.png

image.png

Note that the above error is a failure of Eclipse itself and does not affect the construction and behavior of the application, so there is no problem even if it appears.

② How to start the application is as follows. Right click on the project (1)> Run (2)> Spring Boot Application (3). image.png

After that, check that the application works properly.

(4) Next, change the settings to prevent the project from being built unintentionally. Click “Project” in the menu bar (1) and uncheck “Automatically build” (2). image.png

(5) Let’s make another necessary setting change. Click “Window”> “Preferences” in the menu bar, and uncheck “Build before startup (if necessary)” in “Run/Debug” (1)> “Start” (2) ( ③), click “Apply and Close” (④). image.png

This completes the preparations for upgrading the JDK version.

[2] Install and apply Amazon Corretto 11

Next, install Amazon Corretto 11 and apply it to Eclipse.

(1) Install Amazon Corretto 11. Download Amazon Corretto 11 | aws Let’s download and double-click the installer to start it.

(2) If the wizard starts up, you can proceed with the default settings, but if you reach the “Custom Setup” screen, confirm that the JDK version is “Amazon Corretto JDK 11 distribution” (1). Let’s go. The default installation location is directly under the Amazon Corretto folder under Program Files (②). image.png

(3) After the installation is complete, change the “Installed JRE” of Eclipse. In Eclipse, click “Window” (1)> “Settings” in the menu bar (2). image.png

(4) When the “Settings” window opens, click “Java” (1)> “Installed JRE” (2)> “Add” (3) in that order. image.png

(5) When the “Add JRE” screen appears, select “Standard VM” (1) and click “Next” (2). image.png

(6) When the “Edit JRE” screen appears, click the “Directory” button (1), select the folder of the installed JDK (Amazon Corretto 11) (2), and name it as desired (3) ), click “Finish” (④). image.png

(7) Check the added JDK (1) and click “Apply and Close” (2). image.png

[3] Run the application built with JDK 8 (Amazon Corretto 8) with JDK 11 (Amazon Corretto 11)

After applying Amazon Corretto 11, let’s confirm the operation before rebuilding, that is, using the one built with JDK 8 (Amazon Corretto 8). The confirmation viewpoint is

  • Check for any libraries that need upgrading

It will be.

(1) Start the target application on Eclipse.

(2) If the application starts normally, check the version of the JDK when compiling, just in case, before checking the operation. At the command prompt, execute the Java version check command for any class file under the bin of the target project.

When executing in the class file of the following folder, it is as follows. image.png

Execution command

 & result
> cd C:\pleiades-2020-03\workspace\sample-eb-java\bin\main\jp\co\sample_eb_java\domain\service
> javap -v ShopInformationService.classClassfile /C:/pleiades-2020-03/workspace/sample-eb-java/bin/main/jp/co/sample_eb_java/domain/service/ShopInformationService.class
  Last modified 2020/08/12; size 1957 bytes
  MD5 checksum b6712daccce6cad8628e31007340fcca
  Compiled from "ShopInformationService.java"
public class jp.co.sample_eb_java.domain.service.ShopInformationService
  minor version: 0
  major version: 52
...(Hereinafter omitted)

OK if it is “major version: 52”! By the way, for JDK 11, it is “major version: 55”.

(3) Let’s check the operation. If the behavior is different from when you build it with JDK 8 and start the application and run it, modify it. (This time it was okay.)

[4] Run an application built with JDK 11 (Amazon Corretto 11) with JDK 11 (Amazon Corretto 11)

Next, run the application built with JDK 11 (Amazon Corretto 11) with JDK 11 (Amazon Corretto 11). The confirmation viewpoint is

  • Make sure that obsolete APIs are not used

Will be.

(1) First, change the sourceCompatibility of build.gradle from 1.8 to 11. This setting value will be the Java version used at the time of build, and if not specified, it will be built with the applied JDK version.

build.gradle (before change)


plugins {
id'org.springframework.boot' version '2.3.2.RELEASE'
id'io.spring.dependency-management' version '1.0.9.RELEASE'
id'java'
}

group ='io.code_check.challenge_server'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
...(Hereinafter omitted)

build.gradle (after change)


plugins {
id'org.springframework.boot' version '2.3.2.RELEASE'
id'io.spring.dependency-management' version '1.0.9.RELEASE'
id'java'
}

group ='io.code_check.challenge_server'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
...(Hereinafter omitted)

(2) After saving, right click on “build.gradle” (1)> “Gradle” (2)> “Refresh Gradle project” (3) to update the dependencies. image.png

(3) Clean the project.

(4) Check the error. Check the “Problems” tab and make sure there are no new errors. If an error occurs, fix it by referring to the content of the message (this time it was okay as well.) image.png

(5) Right-click on the target project to start the application.

(6) If the application starts normally, check the version of the JDK at the time of compilation again before checking the operation. At the command prompt, execute the Java version confirmation command for any class file under the project bin.

Execution command

 & result
> cd C:\pleiades-2020-03\workspace\sample-eb-java\bin\main\jp\co\sample_eb_java\domain\service
> javap -v ShopInformationService.class
Classfile /C:/pleiades-2020-03/workspace/sample-eb-java/bin/main/jp/co/sample_eb_java/domain/service/ShopInformationService.class
  Last modified 2020/08/12; size 1957 bytes
  MD5 checksum b6712daccce6cad8628e31007340fcca
  Compiled from "ShopInformationService.java"
public class jp.co.sample_eb_java.domain.service.ShopInformationService
  minor version: 0
  major version: 55
...(Hereinafter omitted)

If it says “major version: 55”, it’s OK!

(7) Check the operation, and if it is different from the expected result, correct the target part. (This one was also fine this time.)

(8) Create a jar file for creating the Elastic Beantalk environment. Move to the project root directory and execute the build command.

If the arrangement is as follows, it will be as follows. image.png

Execution command


> cd C:\pleiades-2020-03\workspace\sample-eb-java
> gradlew build

OK if the result is “BUILD SUCCESS FUL”!

(10) Make sure that the jar file is created under build/libs. (This is used when creating the environment.) image.png

2. Create a Corretto 11 environment with Elastic Beanstalk

Next, we’ll create an environment for the Corretto 11 platform with Elastic Beanstalk.

(1) After logging in to AWS Management Console and opening Elastic Beanstalk, click “Application” in the navigation pane and press the radio button of the project for which you want to create the environment for corretto 11 platform (②) “Action” (③) > “Creating an environment” (4). image.png

(2) Select “Web server environment” (1) and click “Select” (2). image.png

(3) Set as follows and click “Set more options” (⑨)

No Name Settings
Environment name Enter an arbitrary name (different from the existing one)
Platform Java
Platform branch Corretto 11 running on 64bit Amazon Linux 2
Platform version 3.1.0: Recommended version
Application Code Select “Upload Code”
Version label Enter an arbitrary name (different from the existing one)
Source code source Select “Local file” and upload the jar file created in 1-(9) and (10)
File selection 1-Upload the jar file created in (9) and (10)

image.png

(4) In “Setting more options”,

  • ① Software
  • ② Network

Set up.

① After transitioning to the “Set more options” screen, click the “Edit” button of “Software”, set as follows on the “Change software” screen, and click “Save” (③) ..

|No|Name|Settings| |—|—|—| | ① | Log streaming | Check “Enabled” | | ② | Environment properties | Set the same contents as the existing Java 8 platform (use the same RDS) | image.png

② Next, click the “Edit” button of “Network”, set as follows on the “Change Network” screen, and click “Save” (③).

|No|Name|Settings| |—|—|—| | ① | Public IP address | Check | | ② | Availability Zone | Check | image.png

(3) When you return to the “Set more options” screen, click “Create environment” at the bottom right of the scene to create an environment.image.png

(4) After a while, the environment is created. OK if your health is OK! image.png

3. Reset CodePipeline

In the future, we will review the CodePipeline settings so that it will be properly deployed to the environment created in “2. Create Corretto 11 environment with Elastic Beanstalk”.

[1] BuildSpec of CodeBuild

(1) On the management console, open CodeBuild, select the build project used for CI/CD on the Java 8 platform, and click “Edit” (②)> “BuildSpec” (③). image.png

(2) As shown below, change the build command java from corretto8 to corretto11 (①) and click “Update buildspec” (②). image.png

BuildSpec (before change)


version: 0.2

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

BuildSpec (after change)


version: 0.2

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

[2] Deploy destination of CodePipeline

(1) On the management console, search for CodePipeline, open it, and click the target pipeline. image.png

(2) Click “Edit” after transition to the target pipeline screen. image.png

(3) Click “Edit stage” in “Edit: Deploy” (1) and then click the “Edit” button (2). image.png

image.png

(4) After transitioning to the “Edit Action” screen, change “Environment Name” to the environment name created in “2. Create Corretto 11 environment with Elastic Beanstalk” (1) and click “Finish” (2) ). image.png

(5) Click the “Save” button to save the changes. image.png

(6) The contents of build.gradle should have been changed in “1. JDK version upgrade from Amazon Corretto 8 to Amazon Corretto 11”, so let’s commit and push to execute the pipeline. If the deployment is successful as follows (1), click “AWS Elastic Beanstalk” (2). image.png

(7) Click on the target environment as it moves to the “Environment” screen of Elastic Beanstalk. image.png

(8) Confirm that “Health” is “OK”, and confirm that the application operates correctly in the domain (②). image.png

4. Environment URL swap

Swap the environment URL, that is, replace the existing Java 8 platform and the Corretto 11 platform URL created this time. This eliminates the need to change the application URL.

(1) In the console, go to Elastic Beantalk screen, in the “Environment” menu, check the radio button of Java 8 environment (①), click “Action” (②)> “Environment URL” swap (③). image.png

(2) Select the environment created in “2. Create Corretto 11 environment with Elastic Beanstalk” in “Environment name” of “Select environment to swap” (①) and click “Swap” (②). image.png

(3) When you’re done, go to the Corretto 11 platform and make sure the URL in the red box has been changed to the one that was for the Java 8 platform. image.png

(4) As a precaution, let’s confirm the operation in the domain after replacement.

5. Separation of RDS instances

Then separate the RDS instance from the Java 8 platform so that the RDS is not deleted when you exit the environment.

(1) In the Management Console, search for RDS, make a transition, click “Database” in the navigation pane, and then check the radio button of the target DB instance (included in the Java 8 platform) (①)> Click “Action” (②)> “Get Snapshot” (③). image.png

(2) Enter any snapshot name (1) and click “Get snapshot” (2) image.png

(3) On the “Snapshot” screen, confirm that the snapshot has been created. image.png

(4) In the navigation pane, click “Database” (1), check the radio button of the target DB instance (1), and click “Change” (3). image.png

(5) Check “Enable deletion protection” (1) and “Next” (2). image.png

(6) Confirm the contents and click “Change DB Instance”. image.png

6. Remove Java 8 environment

(1) Delete the Java 8 environment that is no longer needed.After clicking “Environment” in the Elastic Beanstalk navigation pane, check the Java 8 environment radio button (1) and click “Action” (2)> “End environment” (3). image.png

(2) After the Java 8 environment has been terminated, confirm that the database instance has not been deleted, and confirm the operation again in the Corretto 11 domain.

7. Clean up

[1] Corretto 11 Platform Environment Removal

(1) Delete the environment in the same way as “6. Delete the Java 8 environment”.

[2] Delete RDS Instance

Since the database instance is separated from the Elastic Beanstalk environment in “5. Separation of RDS Instance”, it will not be deleted as it is. Follow the procedure below.

(1) Go to RDS on the Management Console, click “Database” on the navigation pane, check the radio button of the target DB instance (①), and click “Change” (②). image.png

(2) Uncheck “Enable deletion protection” (1) and “Next” (2). image.png

(3) Check “Summary of changes” (1), select “Apply immediately” (2), and click “Change DB instance” (3). image.png

(4) After returning to the “Database” screen, check the radio button of the target RDS instance and click “Action” (②)> “Delete” to delete (③). image.png

Reference

  • [Java SE platform history aws](https://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/platforms/platform-history-javase.html)
  • [Java support period Qiita](https://qiita.com/yukoba/items/69fe9468b719fa6e69c4)
  • [FAQ for Amazon Corretto aws](https://aws.amazon.com/jp/corretto/faqs/)
  • [AWS Elastic Beanstalk announces general availability of Amazon Linux 2-based Tomcat platform aws](https://aws.amazon.com/jp/about-aws/whats-new/2020/06/aws-elastic-beanstalk-announces-general-availability-of-amazon-linux-2-based-tomcat-platforms/)

Procedure

1. Update JDK from Amazon Corretto 8 to Amazon Corretto 11

  • [Oracle JDK Migration Guide (Release 11) Oracle Help Center](https://docs.oracle.com/javase/jp/11/migrate/index.html)
  • [ Web application of Spring Boot 2.0.x is upgraded to 2.1.x (Part 15) (Change JDK from 8u202 to 11.0.2+9) | Kangaroo’s diary](https://ksby.hatenablog(.com/entry/2019/03/16/144029)
  • [I get an error about an unused database driver IBM Support](https://www.ibm.com/support/pages/%E6%9C%AA%E4%BD%BF%E7%94%A8%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%83%99%E3%83%BC%E3%82%B9%EF%BD%A5%E3%83%89%E3%83%A9%E3%82%A4%E3%83%90%E3%83%BC%E3%81%AB%E9%96%A2%E3%81%99%E3%82%8B%E3%82%A8%E3%83%A9%E3%83%BC%E3%81%8C%E8%A1%A8%E7%A4%BA%E3%81%95%E3%82%(8C%E3%82%8B)
  • [About Eclipse build automatically stack overflow](https://en.stackoverflow.com/questions/6386/eclipse%E3%81%AE%E8%87%AA%E5%8B%95%E7%9A%84%E3%81%AB%E3%83%93%E3%83%AB%E3%83%89%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6)
  • [Check which version of Java class file was compiled Rutake’s tech note](http://blog.rutake.com/techmemo/2016/01/06/java-class%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%8C%E3%81%A9%E3%81%AE%E3%83%90%E3%83%BC%E3%82%B8%E3%83%A7%E3%83%B3%E3%81%A7%E3%82%B3%E3%83%B3%E3%83%91%E3%82%A4%E3%83%AB%E3%81%95%E3%82%8C%E3%81%9F/)
  • [Java version Hishida’s change history](http://www.ne.jp/asahi/hishidama/home/tech/java/version.html)
  • [Creating Eclipse and Intellij IDEA development environment with Gradle Cat lover mobile application developer record](http://kkoudev.github.io/blog/2014/03/22/gradle_ide/)

4. Blue/Green Deployment-Separation of RDS Instance and Swap of Environment URL-

  • [Update Elastic Beanstalk environment platform version aws](https://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/using-features.platform.upgrade.html)
  • [Method 2 – Perform Blue/Green Deployment aws](https://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/using-features.platform.upgrade.html#using-features.platform.upgrade.bluegreen)
  • [Blue/Green deployment using Elastic Beanstalk aws](https://docs.aws.amazon.com/ja_jp/elasticbeanstalk/latest/dg/using-features.CNAMESwap.html)
  • [How can I isolate my Amazon RDS instance from my Elastic Beanstalk environment without downtime, database sync issues, or data loss? aws](https://aws.amazon.com/en/premiumsupport/knowledge-center/decouple-rds-from-beanstalk/)