Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: e2e tests with java 21 #1517

Merged
merged 9 commits into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
@@ -32,13 +32,19 @@ jobs:
e2e:
runs-on: ubuntu-latest
strategy:
max-parallel: 3
max-parallel: 4
matrix:
java: [ 8, 11, 17 ]
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_LAMBDA_RUNTIME_VERSION: ${{ matrix.java }}
permissions:
id-token: write # needed to interact with GitHub's OIDC Token endpoint.
contents: read
@@ -48,7 +54,8 @@ jobs:
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
with:
distribution: 'corretto'
java-version: ${{ 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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,14 @@ 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).

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

Powertools for AWS Lambda (Java) is available in Maven Central. You can use your favourite dependency management tool to install it
10 changes: 9 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -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 [[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

This project separates core utilities that will be available in other runtimes vs general utilities that might not be available across all runtimes.
2 changes: 1 addition & 1 deletion powertools-e2e-tests/pom.xml
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<constructs.version>10.3.0</constructs.version>
<cdk.version>2.100.0</cdk.version>
<cdk.version>2.109.0</cdk.version>
</properties>

<dependencies>
Original file line number Diff line number Diff line change
@@ -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<String> 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,29 +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_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")) {
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() {
Original file line number Diff line number Diff line change
@@ -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;