Skip to content

Commit

Permalink
Merge pull request #1608 from aws-powertools/chore/v2-merge-main-down
Browse files Browse the repository at this point in the history
chore(v2): merge main down
  • Loading branch information
scottgerring authored Mar 18, 2024
2 parents 8f176cc + 4976a5b commit cf8a399
Show file tree
Hide file tree
Showing 13 changed files with 199 additions and 28 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/pr_artifacts_size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
edit-mode: replace
21 changes: 9 additions & 12 deletions .github/workflows/pr_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ 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/**'
- 'powertools-logging/**'
- 'powertools-metrics/**'
- 'powertools-parameters/**'
- 'powertools-serialization/**'
- 'powertools-sqs/**'
- 'powertools-test-suite/**'
- 'powertools-tracing/**'
- 'powertools-validation/**'
- 'examples/**'
Expand All @@ -26,18 +26,19 @@ on:
push:
branches:
- main
- v2
paths:
- 'powertools-batch/**'
- 'powertools-cloudformation/**'
- 'powertools-core/**'
- '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/**'
Expand Down Expand Up @@ -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
Expand Down
93 changes: 93 additions & 0 deletions .github/workflows/pr_build_v2.yml
Original file line number Diff line number Diff line change
@@ -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/
58 changes: 58 additions & 0 deletions .github/workflows/run-e2e-tests-v2.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ on:
push:
branches:
- main
- v2
paths: # add other modules when there are under e2e tests
- 'powertools-e2e-tests/**'
- 'powertools-batch/**'
Expand Down
2 changes: 1 addition & 1 deletion examples/powertools-examples-batch/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.0</version>
<version>3.5.2</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
4 changes: 2 additions & 2 deletions examples/powertools-examples-core-utilities/cdk/infra/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>2.0.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cdk.version>2.100.0</cdk.version>
<cdk.version>2.130.0</cdk.version>
<constructs.version>[10.0.0,11.0.0)</constructs.version>
<junit.version>5.10.0</junit.version>
</properties>
Expand All @@ -25,7 +25,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<version>3.2.0</version>
<configuration>
<mainClass>cdk.CdkApp</mainClass>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

4 changes: 2 additions & 2 deletions examples/powertools-examples-parameters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.11.3</version>
<version>3.11.4</version>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
Expand Down Expand Up @@ -73,7 +73,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- JUnit 5 requires Surefire version 3.1.0 or higher -->
<version>3.1.2</version>
<version>3.2.5</version>
</plugin>
<plugin>
<groupId>dev.aspectj</groupId>
Expand Down
2 changes: 1 addition & 1 deletion examples/powertools-examples-serialization/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.11.3</version>
<version>3.11.4</version>
</dependency>
</dependencies>

Expand Down
4 changes: 2 additions & 2 deletions powertools-e2e-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.109.0</cdk.version>
<cdk.version>2.130.0</cdk.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -159,7 +159,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.1</version>
<version>2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion powertools-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.5</version>
<configuration>
<environmentVariables>
<AWS_LAMBDA_LOG_FORMAT>JSON</AWS_LAMBDA_LOG_FORMAT>
Expand Down
2 changes: 1 addition & 1 deletion powertools-parameters/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<version>3.2.5</version>
<configuration>
<environmentVariables>
<AWS_REGION>eu-central-1</AWS_REGION>
Expand Down

0 comments on commit cf8a399

Please sign in to comment.