From 80f61b23fe0ab12d0688e311f131672c7b886f8e Mon Sep 17 00:00:00 2001 From: Jerome Van Der Linden Date: Thu, 16 Nov 2023 23:29:42 +0100 Subject: [PATCH 1/9] e2e tests with java 21 --- .github/workflows/run-e2e-tests.yml | 2 +- powertools-e2e-tests/pom.xml | 2 +- .../amazon/lambda/powertools/testutils/Infrastructure.java | 2 ++ .../amazon/lambda/powertools/testutils/JavaRuntime.java | 3 ++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml index a2a1b9aec..226f63dd7 100644 --- a/.github/workflows/run-e2e-tests.yml +++ b/.github/workflows/run-e2e-tests.yml @@ -34,7 +34,7 @@ jobs: strategy: max-parallel: 3 matrix: - java: [ 8, 11, 17 ] + java: [ 8, 11, 17, 21 ] name: End-to-end tests java${{ matrix.java }} env: JAVA_VERSION: ${{ matrix.java }} diff --git a/powertools-e2e-tests/pom.xml b/powertools-e2e-tests/pom.xml index 05c544641..8a0b65f32 100644 --- a/powertools-e2e-tests/pom.xml +++ b/powertools-e2e-tests/pom.xml @@ -31,7 +31,7 @@ 1.8 1.8 10.3.0 - 2.100.0 + 2.109.0 diff --git a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java index b1fab2883..a2917735f 100644 --- a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java +++ b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java @@ -523,6 +523,8 @@ private void getJavaRuntime() { runtime = JavaRuntime.JAVA11; } else if (javaVersion.startsWith("17")) { runtime = JavaRuntime.JAVA17; + } else if (javaVersion.startsWith("21")) { + runtime = JavaRuntime.JAVA21; } else { throw new IllegalArgumentException("Unsupported Java version " + javaVersion); } diff --git a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/JavaRuntime.java b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/JavaRuntime.java index c50fcab84..c75682949 100644 --- a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/JavaRuntime.java +++ b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/JavaRuntime.java @@ -20,7 +20,8 @@ public enum JavaRuntime { JAVA8("java8", Runtime.JAVA_8, "1.8"), JAVA8AL2("java8.al2", Runtime.JAVA_8_CORRETTO, "1.8"), JAVA11("java11", Runtime.JAVA_11, "11"), - JAVA17("java17", Runtime.JAVA_17, "17"); + JAVA17("java17", Runtime.JAVA_17, "17"), + JAVA21("java21", Runtime.JAVA_21, "21"); private final String runtime; private final Runtime cdkRuntime; From 856189d7182629e2350d098976b86fbfe09d643e Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 09:25:28 +0100 Subject: [PATCH 2/9] Run Java21 tests using the Java17 compiler --- .github/workflows/run-e2e-tests.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml index 226f63dd7..41156929a 100644 --- a/.github/workflows/run-e2e-tests.yml +++ b/.github/workflows/run-e2e-tests.yml @@ -48,7 +48,11 @@ jobs: uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 with: distribution: 'corretto' - java-version: ${{ matrix.java }} + # If matrix.version is 21, use 17, otherwise use matrix.version + # This is because AspectJ does not yet support weaving with Java21; we want + # to test the Java21 runtime, but we can't yet use the JDK21 compiler. + # https://github.com/eclipse-aspectj/aspectj/issues/260#issuecomment-1815920274 + java-version: ${{ matrix.java == 21 && '17' || matrix.java }} cache: maven - name: Setup AWS credentials uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0 From 1df278cc20994288eab5fa780e97eed0ee2230eb Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 09:28:18 +0100 Subject: [PATCH 3/9] Run all of the E2E tests in parallel, not just the first 3 --- .github/workflows/run-e2e-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml index 41156929a..14f4fca4f 100644 --- a/.github/workflows/run-e2e-tests.yml +++ b/.github/workflows/run-e2e-tests.yml @@ -32,7 +32,7 @@ jobs: e2e: runs-on: ubuntu-latest strategy: - max-parallel: 3 + max-parallel: 4 matrix: java: [ 8, 11, 17, 21 ] name: End-to-end tests java${{ matrix.java }} From 88ecd52018cb94cca69d8b8af93b09a3abe5318f Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 09:35:58 +0100 Subject: [PATCH 4/9] Try again --- .github/workflows/run-e2e-tests.yml | 15 +++++++++------ .../powertools/testutils/Infrastructure.java | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml index 14f4fca4f..f2dc80ad4 100644 --- a/.github/workflows/run-e2e-tests.yml +++ b/.github/workflows/run-e2e-tests.yml @@ -37,8 +37,14 @@ jobs: java: [ 8, 11, 17, 21 ] name: End-to-end tests java${{ matrix.java }} env: - JAVA_VERSION: ${{ matrix.java }} AWS_DEFAULT_REGION: eu-west-1 + + # If matrix.version is 21, use 17, otherwise use matrix.version + # This is because AspectJ does not yet support weaving with Java21; we want + # to test the Java21 runtime, but we can't yet use the JDK21 compiler. + # https://github.com/eclipse-aspectj/aspectj/issues/260#issuecomment-1815920274 + JAVA_VERSION: ${{ (matrix.java == 21 && '17') || matrix.java }} + JAVA_RUNTIME_VERSION: $ {{ matrix.java }} permissions: id-token: write # needed to interact with GitHub's OIDC Token endpoint. contents: read @@ -48,11 +54,8 @@ jobs: uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 with: distribution: 'corretto' - # If matrix.version is 21, use 17, otherwise use matrix.version - # This is because AspectJ does not yet support weaving with Java21; we want - # to test the Java21 runtime, but we can't yet use the JDK21 compiler. - # https://github.com/eclipse-aspectj/aspectj/issues/260#issuecomment-1815920274 - java-version: ${{ matrix.java == 21 && '17' || matrix.java }} + # See comment above on JAVA_VERSION env var + java-version: ${{ (matrix.java == 21 && '17') || matrix.java }} cache: maven - name: Setup AWS credentials uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0 diff --git a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java index a2917735f..71c070294 100644 --- a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java +++ b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java @@ -513,7 +513,7 @@ private Builder() { * Retrieve the java runtime to use for the lambda function. */ private void getJavaRuntime() { - String javaVersion = System.getenv("JAVA_VERSION"); // must be set in GitHub actions + String javaVersion = System.getenv("JAVA_RUNTIME_VERSION"); // must be set in GitHub actions if (javaVersion == null) { throw new IllegalArgumentException("JAVA_VERSION is not set"); } From e7ff13daea374580609190f42264356297d7ff07 Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 09:38:17 +0100 Subject: [PATCH 5/9] . --- .github/workflows/run-e2e-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml index f2dc80ad4..2864de06a 100644 --- a/.github/workflows/run-e2e-tests.yml +++ b/.github/workflows/run-e2e-tests.yml @@ -44,7 +44,7 @@ jobs: # to test the Java21 runtime, but we can't yet use the JDK21 compiler. # https://github.com/eclipse-aspectj/aspectj/issues/260#issuecomment-1815920274 JAVA_VERSION: ${{ (matrix.java == 21 && '17') || matrix.java }} - JAVA_RUNTIME_VERSION: $ {{ matrix.java }} + JAVA_RUNTIME_VERSION: ${{ matrix.java }} permissions: id-token: write # needed to interact with GitHub's OIDC Token endpoint. contents: read From 9dc165df6a44adfddb997fe42cd8c9f9632b333a Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 09:53:47 +0100 Subject: [PATCH 6/9] Let's try again --- .github/workflows/run-e2e-tests.yml | 2 +- .../powertools/testutils/Infrastructure.java | 32 +++++++++++-------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml index 2864de06a..9e71f56af 100644 --- a/.github/workflows/run-e2e-tests.yml +++ b/.github/workflows/run-e2e-tests.yml @@ -44,7 +44,7 @@ jobs: # to test the Java21 runtime, but we can't yet use the JDK21 compiler. # https://github.com/eclipse-aspectj/aspectj/issues/260#issuecomment-1815920274 JAVA_VERSION: ${{ (matrix.java == 21 && '17') || matrix.java }} - JAVA_RUNTIME_VERSION: ${{ matrix.java }} + JAVA_LAMBDA_RUNTIME_VERSION: ${{ matrix.java }} permissions: id-token: write # needed to interact with GitHub's OIDC Token endpoint. contents: read diff --git a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java index 71c070294..11ee24b05 100644 --- a/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java +++ b/powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java @@ -114,6 +114,7 @@ public class Infrastructure { private final String queue; private final String kinesisStream; private final String largeMessagesBucket; + private final JavaRuntime lambdaRuntimeVersion; private String ddbStreamsTableName; private String functionName; private Object cfnTemplate; @@ -124,6 +125,7 @@ private Infrastructure(Builder builder) { this.tracing = builder.tracing; this.envVar = builder.environmentVariables; this.runtime = builder.runtime; + this.lambdaRuntimeVersion = builder.lambdaRuntimeVersion; this.timeout = builder.timeoutInSeconds; this.pathToFunction = builder.pathToFunction; this.idempotencyTable = builder.idemPotencyTable; @@ -204,6 +206,7 @@ public void destroy() { private Stack createStackWithLambda() { boolean createTableForAsyncTests = false; Stack stack = new Stack(app, stackName); + List packagingInstruction = Arrays.asList( "/bin/sh", "-c", @@ -247,7 +250,7 @@ private Stack createStackWithLambda() { .handler("software.amazon.lambda.powertools.e2e.Function::handleRequest") .memorySize(1024) .timeout(Duration.seconds(timeout)) - .runtime(runtime.getCdkRuntime()) + .runtime(lambdaRuntimeVersion.getCdkRuntime()) .environment(envVar) .tracing(tracing ? Tracing.ACTIVE : Tracing.DISABLED) .build(); @@ -504,31 +507,34 @@ public static class Builder { private String queue; private String kinesisStream; private String ddbStreamsTableName; + private JavaRuntime lambdaRuntimeVersion; private Builder() { - getJavaRuntime(); + runtime = mapRuntimeVersion("JAVA_VERSION"); + lambdaRuntimeVersion = mapRuntimeVersion("JAVA_LAMBDA_RUNTIME_VERSION"); } - /** - * Retrieve the java runtime to use for the lambda function. - */ - private void getJavaRuntime() { - String javaVersion = System.getenv("JAVA_RUNTIME_VERSION"); // must be set in GitHub actions + + + private JavaRuntime mapRuntimeVersion(String environmentVariableName) { + String javaVersion = System.getenv(environmentVariableName); // must be set in GitHub actions + JavaRuntime ret = null; if (javaVersion == null) { - throw new IllegalArgumentException("JAVA_VERSION is not set"); + throw new IllegalArgumentException("JAVA_LAMBDA_RUNTIME_VERSION is not set"); } if (javaVersion.startsWith("8")) { - runtime = JavaRuntime.JAVA8AL2; + ret = JavaRuntime.JAVA8AL2; } else if (javaVersion.startsWith("11")) { - runtime = JavaRuntime.JAVA11; + ret = JavaRuntime.JAVA11; } else if (javaVersion.startsWith("17")) { - runtime = JavaRuntime.JAVA17; + ret = JavaRuntime.JAVA17; } else if (javaVersion.startsWith("21")) { - runtime = JavaRuntime.JAVA21; + ret = JavaRuntime.JAVA21; } else { throw new IllegalArgumentException("Unsupported Java version " + javaVersion); } - LOG.debug("Java Version set to {}, using runtime {}", javaVersion, runtime.getRuntime()); + LOG.debug("Java Version set to {}, using runtime variable {}", ret, javaVersion); + return ret; } public Infrastructure build() { From 2b15b3d99684409b2adb75c424e5628bfb2fb923 Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 14:25:51 +0100 Subject: [PATCH 7/9] Add some comment on Java21 to the repo --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 63ba35cc6..c3251997b 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,16 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless **[📜Documentation](https://docs.powertools.aws.dev/lambda-java/)** | **[Feature request](https://github.com/aws-powertools/powertools-lambda-java/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=)** | **[🐛Bug Report](https://github.com/aws-powertools/powertools-lambda-java/issues/new?assignees=&labels=bug%2C+triage&template=bug_report.md&title=)** | **[Detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-aws-lambda-powertools-java/)** +### Java Compatibility +Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the +[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). + +Note: [AspectJ does not yet support Java 21](https://github.com/eclipse-aspectj/aspectj/issues/260). +With Java 21, you can use Powertools features that do not need AspectJ such as +[Batch Processing](https://docs.powertools.aws.dev/lambda-java/guides/batch-processing.html) as you normally would. +If you need aspect features you should use the JDK 17 compiler and target either the Java 17 or Java 21 +runtimes at deployment Lambda. + ### Installation Powertools for AWS Lambda (Java) is available in Maven Central. You can use your favourite dependency management tool to install it From 0432fe13c5517492d4afa7cae37fff83bc756b76 Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 14:35:51 +0100 Subject: [PATCH 8/9] Add caveat about lambda runtimes --- README.md | 8 +++----- docs/index.md | 10 +++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c3251997b..bfef68783 100644 --- a/README.md +++ b/README.md @@ -13,11 +13,9 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the [corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). -Note: [AspectJ does not yet support Java 21](https://github.com/eclipse-aspectj/aspectj/issues/260). -With Java 21, you can use Powertools features that do not need AspectJ such as -[Batch Processing](https://docs.powertools.aws.dev/lambda-java/guides/batch-processing.html) as you normally would. -If you need aspect features you should use the JDK 17 compiler and target either the Java 17 or Java 21 -runtimes at deployment Lambda. +[AspectJ does not yet support Java 21](https://github.com/eclipse-aspectj/aspectj/issues/260). +If you need aspect features such as `@Logging` you should use the JDK 17 compiler and target either the Java 17 or Java 21 +Lambda runtimes. ### Installation diff --git a/docs/index.md b/docs/index.md index 92589be7c..112441efb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -11,10 +11,18 @@ Powertools for AWS Lambda (Java) is a suite of utilities for AWS Lambda Function Powertools for AWS Lambda is also available for [Python](https://docs.powertools.aws.dev/lambda/python/latest/){target="_blank"}, [TypeScript](https://docs.powertools.aws.dev/lambda/typescript/latest/){target="_blank"}, and [.NET](https://docs.powertools.aws.dev/lambda/dotnet/){target="_blank"} -!!! tip "Looking for a quick run through of the core utilities?" +???+ tip "Looking for a quick run through of the core utilities?" Check out [this detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-aws-lambda-powertools-java/) with a practical example. To dive deeper, the [Powertools for AWS Lambda (Java) workshop](https://catalog.us-east-1.prod.workshops.aws/workshops/a7011c82-e4af-4a52-80fa-fcd61f1dacd9/en-US/introduction) is a great next step. +???+ tip "Java Compatability" + Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the + [corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). + + [AspectJ does not yet support Java 21](https://github.com/eclipse-aspectj/aspectj/issues/260). + If you need aspect features such as `@Logging` you should use the JDK 17 compiler and target either the Java 17 or Java 21 + Lambda runtimes. + ## Tenets This project separates core utilities that will be available in other runtimes vs general utilities that might not be available across all runtimes. From 34856c9b9edf551ab012d90b6c5c22c84fe5380d Mon Sep 17 00:00:00 2001 From: Scott Gerring Date: Fri, 17 Nov 2023 14:59:30 +0100 Subject: [PATCH 9/9] Clean up wording a little --- README.md | 6 +++--- docs/index.md | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index bfef68783..bdf779bfb 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,9 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the [corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). -[AspectJ does not yet support Java 21](https://github.com/eclipse-aspectj/aspectj/issues/260). -If you need aspect features such as `@Logging` you should use the JDK 17 compiler and target either the Java 17 or Java 21 -Lambda runtimes. +AspectJ does not yet support Java 21 [[1]](https://github.com/eclipse-aspectj/aspectj/issues/260), [[2]](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md). +If you need to use aspects - either Powertools features leveraging aspects or other libraries - you should use the JDK 17 compiler and target either the Java 17 or Java 21 +Lambda runtimes. ### Installation diff --git a/docs/index.md b/docs/index.md index 112441efb..b1b55e2d6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -19,8 +19,8 @@ Powertools for AWS Lambda (Java) is a suite of utilities for AWS Lambda Function Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the [corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html). - [AspectJ does not yet support Java 21](https://github.com/eclipse-aspectj/aspectj/issues/260). - If you need aspect features such as `@Logging` you should use the JDK 17 compiler and target either the Java 17 or Java 21 + AspectJ does not yet support Java 21 [[1]](https://github.com/eclipse-aspectj/aspectj/issues/260), [[2]](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md). + If you need to use aspects - either Powertools features leveraging aspects or other libraries - you should use the JDK 17 compiler and target either the Java 17 or Java 21 Lambda runtimes. ## Tenets