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

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

--LTS (Long Term Support) version is JDK11 --Even with Amazon Corretto, the support period for Corretto 8 is as short as June 2023, while that for Corretto 11 is as long as August 2024.

For that reason, I would like to support the update of the runtime version as soon as possible.

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

environment

Prerequisites

This article is [Code Pipeline x Elastic Beanstalk] CI / CD Java application to Elastic Beanstalk with Code Pipeline Part 3 | Qiita It will be a sequel position of (Do not clean up the traces of step 6).

Java 8 version 2.10.8 platform environment is assumed to have been created & some work with similar contents is omitted. Please note.

procedure

1. JDK Amazon Corretto 8 → Upgrade to Amazon Corretto 11

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

[1] Advance preparation

(1) First, let's clean the target project with Amazon Corretto 8 applied. Click "Project" (①)> "Clean" (②) 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.

-① No error has occurred -② The application starts and operates normally.

Please check.

(1) You can check the error on the "Problem" tab (④) that appears when you click "Window" (1)> "View View" (2)> "Problem" (3) on the menu bar. image.png

image.png

In addition, 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.

(2) The application startup method is as follows. Right-click on the project (1)> "Run" (2)> "Spring Boot Application" (3). image.png

Then verify that the application works properly.

(4) Next, change the settings to prevent the project from being built unintentionally. Click "Project" on the menu bar (1) and uncheck "Build automatically" (2). image.png

(5) Let's make another necessary setting change. Click "Window"> "Settings" on the menu bar, then uncheck "Build before (if necessary)" in "Run / Debug" (1)> "Start" (2) ((2)) ③), click "Apply and close" (④). image.png

This completes the preparations for the JDK version upgrade.

[2] Installing and applying Amazon Corretto 11

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

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

(2) When the wizard starts up, it is okay if you proceed with the basic defaults, but when you reach the "Custom Setup" screen, check that the JDK version is "Amazon Corretto JDK 11 distribution" (①). Let's go. The default installation destination is directly under the Amazon Corretto folder under Program Files (②). image.png

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

(4) When the "Settings" window appears, click "Java" (1)> "Installed JRE" (2)> "Add" (3). image.png

(5) When the "Add JRE" screen appears, select "Standard VM" (①) and click "Next" (②). image.png

(6) When the "Edit JRE" screen appears, click the "Directory" button (1), select the installed JDK (Amazon Corretto 11) folder (2), and give it an arbitrary JRE name (3). ), Click "Finish" (④). image.png

(7) Check the added JDK (①) and click "Apply and Close" (②). image.png

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

After applying Amazon Corretto 11, let's check the operation before rebuilding, that is, using the one built with JDK 8 (Amazon Corretto 8). The confirmation point of view is

--Check if there are any libraries that need to be upgraded

It will be.

(1) Start the target application on Eclipse.

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

When executing to 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.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: 52
・ ・ ・ (Hereafter, omitted)

If it says "major version: 52", it's OK! </ b> By the way, in the case of JDK 11, it will be "major version: 55".

(3) Let's check the operation. If the behavior is different from when you build & start the application with JDK 8 and run it, fix it. (It was okay this time.)

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

Next, run the application built with JDK 11 (Amazon Corretto 11) on JDK 11 (Amazon Corretto 11). The confirmation point of view is

--Check if obsolete APIs are used

Will be.

(1) First, change the source Compatibility of build.gradle from 1.8 to 11. This setting will be the Java version used at build time, 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'
・ ・ ・ (Hereafter, 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'
・ ・ ・ (Hereafter, omitted)

(2) After saving, right-click (1)> "Gradle" (2)> "Refresh Gradle project" (3) on "build.gradle" to update the dependency. 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, refer to the content of the message and correct it (this time was also okay). image.png

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

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

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
・ ・ ・ (Hereafter, omitted)

If it says "major version: 55", it's OK! </ b>

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

(8) Create a jar file for creating the Elastic Beantalk environment. Go to the root directory of your project and run the build command.

If the layout 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 SUCCESSFUL"! </ b>

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

2. Create a Corretto 11 environment with Elastic Beanstalk

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

(1) Log in to the AWS Management Console, open Elastic Beanstalk, click "Applications" in the navigation pane, and press the radio button of the project for which you want to create an environment for the corretto 11 platform (②) "Action" (③) > "Creating an environment" (④). image.png

(2) Select "Web server environment" (①) and click "Select" (②). image.png

(3) Set as follows and click "Set more options" (9)

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

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 "Valid"
Environment properties Set the same content as the existing Java 8 platform (use the same RDS)

image.png

(2) Next, click the "Edit" button of "Network", set as follows on the "Change network" screen, and click "Save" (③).

No name Settings
Public IP address Put a check
Availability zone Put a 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) The environment will be created after a while. If the health is "OK", it's OK! image.png

3. Reconfigure CodePipeline

In the future, we will review the Code Pipeline settings so that they will be deployed correctly in the environment created in "2. Creating a Corretto 11 environment with Elastic Beanstalk".

[1] CodeBuild BuildSpec

(1) In the management console, open CodeBuild, select the build project you are using when CI / CD to the Java 8 platform, and click "Edit" (②)> "BuildSpec" (③). image.png

(2) Change the java of the build command from corretto8 to corretto11 as shown below (①) 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] CodePipeline deployment destination

(1) In the management console, find CodePipeline, open it, and click the target pipeline. image.png

(2) After transitioning to the screen of the target pipeline, click "Edit". image.png

(3) Click "Edit Stage" of "Edit: Deploy" (1), and click the "Edit" button (2). image.png

image.png

(4) After transitioning to the "Edit Action" screen, change the "Environment Name" to the environment name created in "2. Creating a Corretto 11 Environment with Elastic Beanstalk" (①) and click "Finish" (②). ). image.png

(5) Click the "Save" button to save your changes. image.png

(6) Since the contents of build.gradle should have been changed in "1. Upgrade JDK to Amazon Corretto 8 → Amazon Corretto 11", let's commit, push and execute the pipeline. If the deployment is successful as shown below (1), click "AWS Elastic Beanstalk" (2). image.png

(7) The screen will change to the "Environment" screen of Elastic Beanstalk, so click the target environment. image.png

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

4. Swap environment URL

Swap the environment URLs, that is, swap the URLs of the existing Java 8 platform with the Corretto 11 platform created this time. This eliminates the need to change the URL of your application.

(1) On the console, move to the Elastic Beantalk screen, check the Java 8 environment radio button in the "Environment" menu (1), and click "Action" (2)> Swap "Environment URL". (③). image.png

(2) In "Environment name" of "Selection of environment to swap", select the environment created in "2. Create Corretto 11 environment with Elastic Beanstalk" (①) and click "Swap" (②). image.png

(3) When the work is completed, go to the Corretto 11 platform and confirm that the URL in the red frame has been changed to the URL that was for the Java 8 platform. image.png

(4) Just in case, let's check the operation with the replaced domain.

5. Isolation of RDS instances

Then, isolate the RDS instance from the Java 8 platform so that RDS isn't removed when you exit the environment.

(1) In the management console, search for RDS, transition to it, 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" (②)> "Take snapshot" (③). image.png

(2) Enter an arbitrary snapshot name (①) and click "Take snapshot" (②) 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" (①) and "Next" (②). image.png

(6) Check the contents and click "Change DB Instance". image.png

6. Remove Java 8 environment

(1) Delete the Java 8 environment that you no longer need. After clicking "Environment" in the navigation pane of Elastic Beanstalk, check the radio button of Java 8 environment (①), and click "Action" (②)> "Exit Environment" (③). image.png

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

7. Clean up

[1] Removal of Corretto 11 platform environment

(1) Delete the environment in the same way as "6. Deleting Java 8 environment".

[2] Delete RDS instance

In "5. Isolate RDS Instance", the database instance is isolated from the Elastic Beanstalk environment, so it will not be deleted as it is. Follow the procedure below.

(1) In the management console, transition to RDS, click "Database" in the navigation pane, check the radio button of the target DB instance (①), and click "Change" (②). image.png

(2) Uncheck "Enable deletion protection" (①) and "Next" (②). image.png

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

(4) When you return to the "Database" screen, check the radio button of the target RDS instance and click "Action" (②)> "Delete" to delete it (③). image.png

reference

-Java SE Platform History | aws -Java support period | Qiita -Amazon Corretto Frequently Asked Questions | aws -[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. JDK Amazon Corretto 8 → Upgrade to Amazon Corretto 11

-Oracle JDK Migration Guide (Release 11) | Oracle Help Center

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

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

Recommended Posts