diff --git a/.github/workflows/pr_artifacts_size.yml b/.github/workflows/pr_artifacts_size.yml index 2244f7b06..e7e3158e3 100644 --- a/.github/workflows/pr_artifacts_size.yml +++ b/.github/workflows/pr_artifacts_size.yml @@ -27,6 +27,9 @@ on: jobs: codecheck: runs-on: ubuntu-latest + permissions: + pull-requests: write + issues: read steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - name: Setup java JDK 11 @@ -62,4 +65,4 @@ jobs: comment-id: ${{ steps.find-comment.outputs.comment-id }} issue-number: ${{ github.event.pull_request.number }} body-path: 'report.md' - edit-mode: replace \ No newline at end of file + edit-mode: replace diff --git a/.github/workflows/pr_build.yml b/.github/workflows/pr_build.yml index 4fa8dc7c0..634a4ee0f 100644 --- a/.github/workflows/pr_build.yml +++ b/.github/workflows/pr_build.yml @@ -4,12 +4,10 @@ on: pull_request: branches: - main - - v2 paths: - 'powertools-batch/**' - 'powertools-cloudformation/**' - - 'powertools-core/**' # not in v2 - - 'powertools-common/**' # v2 only + - 'powertools-core/**' - 'powertools-e2e-tests/**' - 'powertools-idempotency/**' - 'powertools-large-messages/**' @@ -17,6 +15,8 @@ on: - 'powertools-metrics/**' - 'powertools-parameters/**' - 'powertools-serialization/**' + - 'powertools-sqs/**' + - 'powertools-test-suite/**' - 'powertools-tracing/**' - 'powertools-validation/**' - 'examples/**' @@ -26,7 +26,6 @@ on: push: branches: - main - - v2 paths: - 'powertools-batch/**' - 'powertools-cloudformation/**' @@ -34,10 +33,12 @@ on: - 'powertools-e2e-tests/**' - 'powertools-idempotency/**' - 'powertools-large-messages/**' + - 'powertools-logging/**' - 'powertools-metrics/**' - 'powertools-parameters/**' - 'powertools-serialization/**' - 'powertools-sqs/**' + - 'powertools-test-suite/**' - 'powertools-tracing/**' - 'powertools-validation/**' - 'examples/**' @@ -67,18 +68,14 @@ jobs: java-version: ${{ matrix.java }} cache: 'maven' - name: Build with Maven - if: ${{ matrix.java == '8' }} # If 8 exclude the examples directory - run: mvn -B install --file pom.xml -pl '!software.amazon.lambda.examples:powertools-examples-idempotency,!software.amazon.lambda.examples:powertools-examples-batch,!software.amazon.lambda.examples:powertools-examples-cloudformation,!software.amazon.lambda.examples:powertools-examples-core-utilities-cdk,!software.amazon.lambda.examples:powertools-examples-core-utilities-sam,!software.amazon.lambda.examples:powertools-examples-core-utilities-serverless,!software.amazon.lambda.examples:powertools-examples-core-utilities-terraform,!software.amazon.lambda.examples:powertools-examples-parameters,!software.amazon.lambda.examples:powertools-examples-serialization,!software.amazon.lambda.examples:powertools-examples-validation,!software.amazon.lambda.examples:cdk,!software.amazon.lambda:powertools-examples' - - name: Build with Maven - if: ${{ matrix.java != '8' }} # If not 8 don't exclude the examples directory run: mvn -B install --file pom.xml - name: Build Gradle Example - Java - if: ${{ matrix.java != '8' }} - working-directory: examples/powertools-examples-core-utilities/gradle + if: ${{ matrix.java == '8' }} # Gradle example can only be built on Java 8 + working-directory: examples/powertools-examples-core/gradle run: ./gradlew build - name: Build Gradle Example - Kotlin - if: ${{ matrix.java != '8' }} - working-directory: examples/powertools-examples-core-utilities/kotlin + if: ${{ matrix.java == '8' }} # Gradle example can only be built on Java 8 + working-directory: examples/powertools-examples-core/kotlin run: ./gradlew build - name: Upload coverage to Codecov uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 diff --git a/.github/workflows/pr_build_v2.yml b/.github/workflows/pr_build_v2.yml new file mode 100644 index 000000000..2079bcb6b --- /dev/null +++ b/.github/workflows/pr_build_v2.yml @@ -0,0 +1,93 @@ +name: Build + +on: + pull_request: + branches: + - v2 + paths: + - 'powertools-batch/**' + - 'powertools-cloudformation/**' + - 'powertools-common/**' + - 'powertools-e2e-tests/**' + - 'powertools-idempotency/**' + - 'powertools-large-messages/**' + - 'powertools-logging/**' + - 'powertools-metrics/**' + - 'powertools-parameters/**' + - 'powertools-serialization/**' + - 'powertools-tracing/**' + - 'powertools-validation/**' + - 'examples/**' + - 'pom.xml' + - 'examples/pom.xml' + - '.github/workflows/**' + push: + branches: + - v2 + paths: + - 'powertools-batch/**' + - 'powertools-cloudformation/**' + - 'powertools-common/**' + - 'powertools-e2e-tests/**' + - 'powertools-idempotency/**' + - 'powertools-large-messages/**' + - 'powertools-logging/**' + - 'powertools-metrics/**' + - 'powertools-parameters/**' + - 'powertools-serialization/**' + - 'powertools-tracing/**' + - 'powertools-validation/**' + - 'examples/**' + - 'pom.xml' + - 'examples/pom.xml' + - '.github/workflows/**' +jobs: + build-corretto: + runs-on: ubuntu-latest + strategy: + max-parallel: 5 + matrix: + java: [11, 17, 21] + name: Java ${{ matrix.java }} + env: + JAVA: ${{ matrix.java }} + AWS_REGION: eu-west-1 + permissions: + id-token: write # needed to interact with GitHub's OIDC Token endpoint. + contents: read + steps: + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - name: Setup java + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 + with: + distribution: 'corretto' + java-version: ${{ matrix.java }} + cache: 'maven' + - name: Build with Maven + run: mvn -B install --file pom.xml + - name: Build Gradle Example - Java + working-directory: examples/powertools-examples-core-utilities/gradle + run: ./gradlew build + - name: Build Gradle Example - Kotlin + working-directory: examples/powertools-examples-core-utilities/kotlin + run: ./gradlew build + - name: Upload coverage to Codecov + uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1 + if: ${{ matrix.java == '11' }} # publish results once + with: + files: ./powertools-cloudformation/target/site/jacoco/jacoco.xml,./powertools-core/target/site/jacoco/jacoco.xml,./powertools-idempotency/target/site/jacoco/jacoco.xml,./powertools-logging/target/site/jacoco/jacoco.xml,./powertools-metrics/target/site/jacoco/jacoco.xml,./powertools-parameters/target/site/jacoco/jacoco.xml,./powertools-serialization/target/site/jacoco/jacoco.xml,./powertools-sqs/target/site/jacoco/jacoco.xml,./powertools-tracing/target/site/jacoco/jacoco.xml,./powertools-validation/target/site/jacoco/jacoco.xml,./powertools-large-messages/target/site/jacoco/jacoco.xml,./powertools-batch/target/site/jacoco/jacoco.xml + savepr: + runs-on: ubuntu-latest + name: Save PR number if running on PR by dependabot + if: github.actor == 'dependabot[bot]' + steps: + - name: Create Directory and save issue + run: | + mkdir -p ./pr + echo ${{ github.event.number }} + echo ${{ github.event.number }} > ./pr/NR + - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 + name: Upload artifact + with: + name: pr + path: pr/ diff --git a/.github/workflows/run-e2e-tests-v2.yml b/.github/workflows/run-e2e-tests-v2.yml new file mode 100644 index 000000000..255c89cfe --- /dev/null +++ b/.github/workflows/run-e2e-tests-v2.yml @@ -0,0 +1,58 @@ +name: Run end-to-end tests + +on: + workflow_dispatch: + + push: + branches: + - v2 + paths: # add other modules when there are under e2e tests + - 'powertools-e2e-tests/**' + - 'powertools-batch/**' + - 'powertools-core/**' + - 'powertools-common/**' + - 'powertools-idempotency/**' + - 'powertools-large-message/**' + - 'powertools-logging/**' + - 'powertools-metrics/**' + - 'powertools-parameters/**' + - 'powertools-serialization/**' + - 'powertools-tracing/**' + - 'pom.xml' + - '.github/workflows/**' + + pull_request: + branches: + - v2 + paths: + - 'powertools-e2e-tests/**' + +jobs: + e2e: + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + java: [ 11, 17, 21 ] + name: End-to-end tests java${{ matrix.java }} + env: + AWS_DEFAULT_REGION: eu-west-1 + JAVA_VERSION: ${{ matrix.java }} + permissions: + id-token: write # needed to interact with GitHub's OIDC Token endpoint. + contents: read + steps: + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 + - name: Setup java + uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0 + with: + distribution: 'corretto' + java-version: ${{ matrix.java }} + cache: maven + - name: Setup AWS credentials + uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0 + with: + role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }} + aws-region: ${{ env.AWS_DEFAULT_REGION }} + - name: Run e2e test with Maven + run: mvn -DskipTests install --file pom.xml && mvn -Pe2e -B verify --file powertools-e2e-tests/pom.xml \ No newline at end of file diff --git a/.github/workflows/run-e2e-tests.yml b/.github/workflows/run-e2e-tests.yml index 5c7bc0b71..b358fe355 100644 --- a/.github/workflows/run-e2e-tests.yml +++ b/.github/workflows/run-e2e-tests.yml @@ -6,7 +6,6 @@ on: push: branches: - main - - v2 paths: # add other modules when there are under e2e tests - 'powertools-e2e-tests/**' - 'powertools-batch/**' diff --git a/examples/powertools-examples-batch/pom.xml b/examples/powertools-examples-batch/pom.xml index 159ff52cd..70a4a6e3f 100644 --- a/examples/powertools-examples-batch/pom.xml +++ b/examples/powertools-examples-batch/pom.xml @@ -109,7 +109,7 @@ org.apache.maven.plugins maven-shade-plugin - 3.5.0 + 3.5.2 package diff --git a/examples/powertools-examples-core-utilities/cdk/infra/pom.xml b/examples/powertools-examples-core-utilities/cdk/infra/pom.xml index f4d82141b..2dd61753a 100644 --- a/examples/powertools-examples-core-utilities/cdk/infra/pom.xml +++ b/examples/powertools-examples-core-utilities/cdk/infra/pom.xml @@ -7,7 +7,7 @@ 2.0.0-SNAPSHOT UTF-8 - 2.100.0 + 2.130.0 [10.0.0,11.0.0) 5.10.0 @@ -25,7 +25,7 @@ org.codehaus.mojo exec-maven-plugin - 3.1.0 + 3.2.0 cdk.CdkApp diff --git a/examples/powertools-examples-core-utilities/sam/src/main/java/helloworld/AppStream.java b/examples/powertools-examples-core-utilities/sam/src/main/java/helloworld/AppStream.java index 401ef8c48..94806cc38 100644 --- a/examples/powertools-examples-core-utilities/sam/src/main/java/helloworld/AppStream.java +++ b/examples/powertools-examples-core-utilities/sam/src/main/java/helloworld/AppStream.java @@ -17,22 +17,43 @@ import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestStreamHandler; import com.fasterxml.jackson.databind.ObjectMapper; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.util.Map; +import java.nio.charset.StandardCharsets; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import software.amazon.lambda.powertools.logging.Logging; import software.amazon.lambda.powertools.metrics.Metrics; +import java.io.InputStreamReader; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; + public class AppStream implements RequestStreamHandler { private static final ObjectMapper mapper = new ObjectMapper(); + private final static Logger log = LogManager.getLogger(AppStream.class); @Override @Logging(logEvent = true) @Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true) - public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException { - Map map = mapper.readValue(input, Map.class); + // RequestStreamHandler can be used instead of RequestHandler for cases when you'd like to deserialize request body or serialize response body yourself, instead of allowing that to happen automatically + // Note that you still need to return a proper JSON for API Gateway to handle + // See Lambda Response format for examples: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html + public void handleRequest(InputStream input, OutputStream output, Context context) { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)); + PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)))) { - System.out.println(map.size()); + log.info("Received: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapper.readTree(reader))); + + writer.write("{\"body\": \"" + System.currentTimeMillis() + "\"} "); + } catch (IOException e) { + log.error("Something has gone wrong: ", e); + } } } + diff --git a/examples/powertools-examples-parameters/pom.xml b/examples/powertools-examples-parameters/pom.xml index a08747ff2..928e56e3a 100644 --- a/examples/powertools-examples-parameters/pom.xml +++ b/examples/powertools-examples-parameters/pom.xml @@ -38,7 +38,7 @@ com.amazonaws aws-lambda-java-events - 3.11.3 + 3.11.4 org.aspectj @@ -73,7 +73,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.2 + 3.2.5 dev.aspectj diff --git a/examples/powertools-examples-serialization/pom.xml b/examples/powertools-examples-serialization/pom.xml index 106fe7cbb..96afc3ea0 100644 --- a/examples/powertools-examples-serialization/pom.xml +++ b/examples/powertools-examples-serialization/pom.xml @@ -31,7 +31,7 @@ com.amazonaws aws-lambda-java-events - 3.11.3 + 3.11.4 diff --git a/powertools-e2e-tests/pom.xml b/powertools-e2e-tests/pom.xml index 92d8f8291..20679d64f 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.109.0 + 2.130.0 @@ -159,7 +159,7 @@ org.yaml snakeyaml - 2.1 + 2.2 test diff --git a/powertools-logging/pom.xml b/powertools-logging/pom.xml index 43c65a3b0..a1148a9cd 100644 --- a/powertools-logging/pom.xml +++ b/powertools-logging/pom.xml @@ -108,7 +108,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.1.2 + 3.2.5 JSON diff --git a/powertools-parameters/pom.xml b/powertools-parameters/pom.xml index 6c90e30a8..0f2b37151 100644 --- a/powertools-parameters/pom.xml +++ b/powertools-parameters/pom.xml @@ -80,7 +80,7 @@ maven-surefire-plugin - 3.1.2 + 3.2.5 eu-central-1