Skip to content

Commit 1813e5f

Browse files
scottgerringjasoniharrisJason HarrisJason Harrisjeromevdl
authored
chore(v2): Merge down from main (#1574)
* docs: HelloWorldStreamFunction in examples fails with sam (#1532) * Setting up Kotlin environment. Converting test to Kotlin. * Deploying via SAM successfully. * Added Kotlin example. * Removing unused Gradle build file. * Adding SAM template so can be used as an existing project and Java target compatibility * Adding SAM template so can be used as an existing project * Updating guidance to use SAM for build and deploy * Restructuring separate Java and Kotlin examples. * Updating core examples readme to represent new structure for Java and Kotlin examples. * Refactoring application code for efficiency, updating build to cover tests too and is more idiomatic and readme to be more descriptive * Updating to fix trailing \n * Updating guidance to be more specific for examples * Adopting new mechanism for specifying jvm target. * accommodating new project structure * Fixing link typo after refactoring * Setting up Kotlin environment. Converting test to Kotlin. * Deploying via SAM successfully. * Added Kotlin example. * Removing unused Gradle build file. * Adding SAM template so can be used as an existing project and Java target compatibility * Adding SAM template so can be used as an existing project * Updating guidance to use SAM for build and deploy * Restructuring separate Java and Kotlin examples. * Updating core examples readme to represent new structure for Java and Kotlin examples. * Refactoring application code for efficiency, updating build to cover tests too and is more idiomatic and readme to be more descriptive * Updating to fix trailing \n * Updating guidance to be more specific for examples * Adopting new mechanism for specifying jvm target. * accommodating new project structure * Fixing link typo after refactoring * Flattening structure back to original to make merging easier for v2 * Adding build for Kotlin Gradle * Adding build for Kotlin Gradle - Restructuring Java examples to v1 approach * Correcting paths * Adding SNAPSHOT support and local capability for Maven. Testing using Java 1.8 * Reviewed and updated against PR comments. * Un-commenting examples * Adding validation step for IaC SAM * Adding Terraform for Java projects IaC validator and linter * Adding additional projects for SAM validation and matrix approach * Refactoring stream function to process input logging example with a Lambda Function URL instead of APIGW. * Demonstrating Java streaming response * Refactoring stream function to process input logging example to return * Update CONTRIBUTING.md * fix: get trace id from system property when env var is not set (#1503) * fix: check if XRAY Trace ID is present in System property * chore: remove erroneous extra char in tests * fix #1500 (#1506) * feat: Add support for POWERTOOLS_LOGGER_LOG_EVENT (#1510) * chore: Addition of Warn Message If Invalid Annotation Key While Tracing #1511 (#1512) * feat: ALC (#1514) * handle AWS_LAMBDA_LOG configuration * ALC documentation + code review * update doc * chore:Prep release 1.18.0 (#1515) * chore:prep release 1.18.0 * update version * update version in kotlin example * maven local repo in gradle example * update changelog --------- Co-authored-by: scottgerring <[email protected]> * chore: update version to next snapshot: 1-19.0-SNAPSHOT (#1516) * update version to next snapshot: 1-19.0-SNAPSHOT * update version to next snapshot: 1-19.0-SNAPSHOT * update version to next snapshot: 1-19.0-SNAPSHOT * building only for LTS * Add some more margin to the test pause (#1518) * test: e2e tests with java 21 (#1517) * e2e tests with java 21 * Run Java21 tests using the Java17 compiler * Run all of the E2E tests in parallel, not just the first 3 * Try again * . * Let's try again * Add some comment on Java21 to the repo * Add caveat about lambda runtimes * Clean up wording a little --------- Co-authored-by: Scott Gerring <[email protected]> * update doc for ALC (#1520) * chore: Testing java21 aspectj pre-release (#1519) * e2e tests with java 21 * use aspectj 1.9.21-SNAPSHOT * Fix log4j2.xml missing in logging test for java21 * rollback double runtime * remove comment * keep aspectj 1.9.7 in parent for java8 compatibility * use M1 instead of snapshot * update documentation for aspectj * update documentation for aspectj --------- Co-authored-by: Jerome Van Der Linden <[email protected]> * chore: Remove build cruft * Adding context for using RequestStreamHandler * removing pr_lint * Update examples/powertools-examples-core/sam/src/main/java/helloworld/AppStream.java Clarify usage of RequestStreamHandler. Co-authored-by: Alexey Soshin <[email protected]> --------- Co-authored-by: Jason Harris <[email protected]> Co-authored-by: Scott Gerring <[email protected]> Co-authored-by: Jason Harris <[email protected]> Co-authored-by: Jérôme Van Der Linden <[email protected]> Co-authored-by: Michele Ricciardi <[email protected]> Co-authored-by: Alexey Soshin <[email protected]> Co-authored-by: jdoherty <[email protected]> Co-authored-by: Scott Gerring <[email protected]> Co-authored-by: Jerome Van Der Linden <[email protected]> * deps: bump aspectj to 1.9.21 for jdk21 (#1536) * chore: SAM and Terraform IaC extracted from pr_build and simplified approach. (#1533) * SAM and Terraform IaC extracted from pr_build and simplified approach. * Update .github/workflows/pr_iac_lint.yml Co-authored-by: Scott Gerring <[email protected]> --------- Co-authored-by: Jason Harris <[email protected]> Co-authored-by: Scott Gerring <[email protected]> * chore: Remove empty CDK test (#1542) * Remove CDK test * Build core utilities so that sam validator can find them * Remove CDK test * Ok just build it all * Remove the plan ... * Remove terraform plan from iac lint --------- Co-authored-by: Jérôme Van Der Linden <[email protected]> * dependabot on v2 branch (#1548) * chore: remove unecessary creds acquisition (#1572) * Merge from main --------- Co-authored-by: Jason Harris <[email protected]> Co-authored-by: Jason Harris <[email protected]> Co-authored-by: Jason Harris <[email protected]> Co-authored-by: Jérôme Van Der Linden <[email protected]> Co-authored-by: Michele Ricciardi <[email protected]> Co-authored-by: Alexey Soshin <[email protected]> Co-authored-by: jdoherty <[email protected]> Co-authored-by: Jerome Van Der Linden <[email protected]>
1 parent 8151421 commit 1813e5f

File tree

8 files changed

+112
-87
lines changed

8 files changed

+112
-87
lines changed

Diff for: .github/dependabot.yml

+9
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,12 @@ updates:
1111
# Ignore Mockito 5.X.X as it does not support Java 8
1212
- dependency-name: "org.mockito:mockito-*"
1313
update-types: ["version-update:semver-major"]
14+
15+
- package-ecosystem: "maven"
16+
directory: "/"
17+
target-branch: "v2"
18+
schedule:
19+
interval: "weekly"
20+
labels:
21+
- "maven"
22+
- "dependencies"

Diff for: .github/workflows/pr_build.yml

-27
Original file line numberDiff line numberDiff line change
@@ -80,33 +80,6 @@ jobs:
8080
if: ${{ matrix.java != '8' }}
8181
working-directory: examples/powertools-examples-core-utilities/kotlin
8282
run: ./gradlew build
83-
- name: Setup Terraform
84-
if: ${{ matrix.java == '11' }}
85-
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 #v2.0.3
86-
- name: Setup AWS credentials
87-
if: ${{ matrix.java == '11' }}
88-
uses: aws-actions/configure-aws-credentials@5fd3084fc36e372ff1fff382a39b10d03659f355 # v2.2.0
89-
with:
90-
role-to-assume: ${{ secrets.AWS_ROLE_ARN_TO_ASSUME }}
91-
aws-region: ${{ env.AWS_REGION }}
92-
- name: Terraform validate
93-
working-directory: examples/powertools-examples-core-utilities/terraform
94-
if: ${{ matrix.java == '11' }}
95-
run: |
96-
terraform -version
97-
terraform init -backend=false
98-
terraform validate
99-
terraform plan
100-
- name: Setup Terraform lint
101-
if: ${{ matrix.java == '11' }}
102-
uses: terraform-linters/setup-tflint@a5a1af8c6551fb10c53f1cd4ba62359f1973746f # v3.1.1
103-
- name: Terraform lint
104-
working-directory: examples/powertools-examples-core-utilities/terraform
105-
if: ${{ matrix.java == '11' }}
106-
run: |
107-
tflint --version
108-
tflint --init
109-
tflint -f compact
11083
- name: Upload coverage to Codecov
11184
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
11285
if: ${{ matrix.java == '11' }} # publish results once

Diff for: .github/workflows/pr_iac_lint.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Validate IaC
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- v2
8+
pull_request:
9+
branches:
10+
- main
11+
- v2
12+
paths:
13+
- 'examples/**'
14+
jobs:
15+
linter:
16+
runs-on: ubuntu-latest
17+
strategy:
18+
matrix:
19+
project: ["sam", "gradle", "kotlin"]
20+
steps:
21+
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
22+
- name: Setup java JDK
23+
uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
24+
with:
25+
distribution: 'corretto'
26+
java-version: 11
27+
- name: Build Project
28+
working-directory: .
29+
run: |
30+
mvn install -DskipTests
31+
- name: Run SAM validator to check syntax of IaC templates - Java
32+
working-directory: examples/powertools-examples-core/${{ matrix.project }}
33+
run: |
34+
sam build
35+
sam validate --lint
36+
- name: Setup Terraform
37+
uses: hashicorp/setup-terraform@633666f66e0061ca3b725c73b2ec20cd13a8fdd1 #v2.0.3
38+
- name: Run Terraform validator to check syntax of IaC templates and produce a plan of changes
39+
working-directory: examples/powertools-examples-core/terraform
40+
run: |
41+
mvn install
42+
terraform -version
43+
terraform init -backend=false
44+
terraform validate
45+
- name: Setup Terraform lint
46+
uses: terraform-linters/setup-tflint@a5a1af8c6551fb10c53f1cd4ba62359f1973746f # v3.1.1
47+
- name: Run Terraform lint to check for best practices, errors, deprecated syntax etc.
48+
working-directory: examples/powertools-examples-core/terraform
49+
run: |
50+
tflint --version
51+
tflint --init
52+
tflint -f compact

Diff for: docs/index.md

-3
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,6 @@ Use the following [dependency matrix](https://github.com/eclipse-aspectj/aspectj
306306
| `11-17` | `1.9.20.1` |
307307
| `21` | `1.9.21` |
308308

309-
_Note: 1.9.21 is not yet available and Java 21 not yet officially supported by aspectj, but you can already use the `1.9.21.M1`_
310-
311-
312309
## Environment variables
313310

314311
!!! info

Diff for: examples/powertools-examples-core-utilities/cdk/app/src/main/java/helloworld/AppStream.java

+25-4
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,43 @@
1717
import com.amazonaws.services.lambda.runtime.Context;
1818
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
1919
import com.fasterxml.jackson.databind.ObjectMapper;
20+
2021
import java.io.IOException;
2122
import java.io.InputStream;
2223
import java.io.OutputStream;
23-
import java.util.Map;
24+
import java.nio.charset.StandardCharsets;
25+
26+
import org.apache.logging.log4j.LogManager;
27+
import org.apache.logging.log4j.Logger;
2428
import software.amazon.lambda.powertools.logging.Logging;
2529
import software.amazon.lambda.powertools.metrics.Metrics;
2630

31+
import java.io.InputStreamReader;
32+
import java.io.BufferedReader;
33+
import java.io.BufferedWriter;
34+
import java.io.OutputStreamWriter;
35+
import java.io.PrintWriter;
36+
2737
public class AppStream implements RequestStreamHandler {
2838
private static final ObjectMapper mapper = new ObjectMapper();
39+
private final static Logger log = LogManager.getLogger(AppStream.class);
2940

3041
@Override
3142
@Logging(logEvent = true)
3243
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
33-
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
34-
Map map = mapper.readValue(input, Map.class);
44+
// 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
45+
// Note that you still need to return a proper JSON for API Gateway to handle
46+
// See Lambda Response format for examples: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
47+
public void handleRequest(InputStream input, OutputStream output, Context context) {
48+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
49+
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)))) {
3550

36-
System.out.println(map.size());
51+
log.info("Received: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapper.readTree(reader)));
52+
53+
writer.write("{\"body\": \"" + System.currentTimeMillis() + "\"} ");
54+
} catch (IOException e) {
55+
log.error("Something has gone wrong: ", e);
56+
}
3757
}
3858
}
59+
Original file line numberDiff line numberDiff line change
@@ -1,48 +0,0 @@
1-
/*
2-
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3-
* Licensed under the Apache License, Version 2.0 (the
4-
* "License"); you may not use this file except in compliance
5-
* with the License. You may obtain a copy of the License at
6-
* http://www.apache.org/licenses/LICENSE-2.0
7-
* Unless required by applicable law or agreed to in writing, software
8-
* distributed under the License is distributed on an "AS IS" BASIS,
9-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10-
* See the License for the specific language governing permissions and
11-
* limitations under the License.
12-
*
13-
*/
14-
15-
package cdk;
16-
17-
import java.util.HashMap;
18-
import java.util.Map;
19-
import org.junit.jupiter.api.Test;
20-
import software.amazon.awscdk.App;
21-
import software.amazon.awscdk.assertions.Template;
22-
23-
public class CdkStackTest {
24-
25-
@Test
26-
public void testStack() {
27-
App app = new App();
28-
CdkStack stack = new CdkStack(app, "test");
29-
30-
Template template = Template.fromStack(stack);
31-
32-
// There should be 2 lambda functions, one to handle regular input, and another for streaming
33-
template.resourceCountIs("AWS::Lambda::Function", 2);
34-
35-
// API Gateway should exist
36-
template.resourceCountIs("AWS::ApiGateway::RestApi", 1);
37-
38-
// API Gateway should have a path pointing to the regular Lambda
39-
Map<String, String> resourceProperties = new HashMap<>();
40-
resourceProperties.put("PathPart", "hello");
41-
template.hasResourceProperties("AWS::ApiGateway::Resource", resourceProperties);
42-
43-
// API Gateway should have a path pointing to the streaming Lambda
44-
resourceProperties = new HashMap<>();
45-
resourceProperties.put("PathPart", "hellostream");
46-
template.hasResourceProperties("AWS::ApiGateway::Resource", resourceProperties);
47-
}
48-
}

Diff for: examples/powertools-examples-core-utilities/gradle/src/main/java/helloworld/AppStream.java

+25-4
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,43 @@
1717
import com.amazonaws.services.lambda.runtime.Context;
1818
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
1919
import com.fasterxml.jackson.databind.ObjectMapper;
20+
2021
import java.io.IOException;
2122
import java.io.InputStream;
2223
import java.io.OutputStream;
23-
import java.util.Map;
24+
import java.nio.charset.StandardCharsets;
25+
26+
import org.apache.logging.log4j.LogManager;
27+
import org.apache.logging.log4j.Logger;
2428
import software.amazon.lambda.powertools.logging.Logging;
2529
import software.amazon.lambda.powertools.metrics.Metrics;
2630

31+
import java.io.InputStreamReader;
32+
import java.io.BufferedReader;
33+
import java.io.BufferedWriter;
34+
import java.io.OutputStreamWriter;
35+
import java.io.PrintWriter;
36+
2737
public class AppStream implements RequestStreamHandler {
2838
private static final ObjectMapper mapper = new ObjectMapper();
39+
private final static Logger log = LogManager.getLogger(AppStream.class);
2940

3041
@Override
3142
@Logging(logEvent = true)
3243
@Metrics(namespace = "ServerlessAirline", service = "payment", captureColdStart = true)
33-
public void handleRequest(InputStream input, OutputStream output, Context context) throws IOException {
34-
Map map = mapper.readValue(input, Map.class);
44+
// 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
45+
// Note that you still need to return a proper JSON for API Gateway to handle
46+
// See Lambda Response format for examples: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
47+
public void handleRequest(InputStream input, OutputStream output, Context context) {
48+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8));
49+
PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8)))) {
3550

36-
System.out.println(map.size());
51+
log.info("Received: " + mapper.writerWithDefaultPrettyPrinter().writeValueAsString(mapper.readTree(reader)));
52+
53+
writer.write("{\"body\": \"" + System.currentTimeMillis() + "\"} ");
54+
} catch (IOException e) {
55+
log.error("Something has gone wrong: ", e);
56+
}
3757
}
3858
}
59+

Diff for: powertools-e2e-tests/handlers/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
<jdk>[21,)</jdk>
214214
</activation>
215215
<properties>
216-
<aspectj.version>1.9.21.M1</aspectj.version>
216+
<aspectj.version>1.9.21</aspectj.version>
217217
</properties>
218218
</profile>
219219
</profiles>

0 commit comments

Comments
 (0)