diff --git a/.github/workflows/pr_artifacts_size.yml b/.github/workflows/pr_artifacts_size.yml
new file mode 100644
index 000000000..cbacd78da
--- /dev/null
+++ b/.github/workflows/pr_artifacts_size.yml
@@ -0,0 +1,57 @@
+name: Artifacts Size
+
+on:
+ pull_request:
+ branches:
+ - master
+ paths:
+ - 'powertools-cloudformation/**'
+ - 'powertools-core/**'
+ - 'powertools-serialization/**'
+ - 'powertools-logging/**'
+ - 'powertools-sqs/**'
+ - 'powertools-tracing/**'
+ - 'powertools-validation/**'
+ - 'powertools-parameters/**'
+ - 'powertools-idempotency/**'
+ - 'powertools-metrics/**'
+ - 'pom.xml'
+jobs:
+ codecheck:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
+ - name: Setup java JDK 11
+ uses: actions/setup-java@5ffc13f4174014e2d4d4572b3d74c3fa61aeb2c2 # v3.11.0
+ with:
+ distribution: 'corretto'
+ java-version: 11
+ - name: Build with Maven
+ run: mvn clean package --file pom.xml -DskipTests
+ - name: Get artifacts size & build report
+ id: artifacts-size-report
+ run: |
+ echo '## :floppy_disk: Artifacts Size Report' > report.md
+ echo '| Module | Version | Size (KB) |' >> report.md
+ echo '| --- | --- | --- |' >> report.md
+ artifact_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
+ for artifact in $(cat target/powertools-parent-*.buildinfo | grep 'outputs.*.jar' | grep -v 'sources.jar'); do
+ artifact_name=$(echo "$artifact" | cut -d '=' -f2)
+ artifact_name=${artifact_name%-$artifact_version.jar}
+ artifact_size=$(grep "${artifact%%.filename*}.length" target/powertools-parent-*.buildinfo | cut -d '=' -f2)
+ printf "| %s | %s | %.2f |\n" "$artifact_name" "$artifact_version" "$(bc <<< "scale=2; $artifact_size/1000")" >> report.md
+ done
+ - name: Find potential existing report
+ uses: peter-evans/find-comment@a54c31d7fa095754bfef525c0c8e5e5674c4b4b1 # 2.4.0
+ id: find-comment
+ with:
+ issue-number: ${{ github.event.pull_request.number }}
+ comment-author: 'github-actions[bot]'
+ body-includes: Artifacts Size Report
+ - name: Write artifacts size report in comment
+ uses: peter-evans/create-or-update-comment@c6c9a1a66007646a28c153e2a8580a5bad27bcfa # 3.0.2
+ with:
+ 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
diff --git a/.github/workflows/build.yml b/.github/workflows/pr_build.yml
similarity index 100%
rename from .github/workflows/build.yml
rename to .github/workflows/pr_build.yml
diff --git a/docs/core/logging.md b/docs/core/logging.md
index 09714a512..2df9a4529 100644
--- a/docs/core/logging.md
+++ b/docs/core/logging.md
@@ -347,7 +347,7 @@ You can set a Correlation ID using `correlationIdPath` attribute by passing a [J
"functionName": "test",
"functionMemorySize": 128,
"functionArn": "arn:aws:lambda:eu-west-1:12345678910:function:test",
- "lambda_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72",
+ "function_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72",
"correlation_id": "correlation_id_value"
}
```
@@ -397,7 +397,7 @@ for known event sources, where either a request ID or X-Ray Trace ID are present
"functionName": "test",
"functionMemorySize": 128,
"functionArn": "arn:aws:lambda:eu-west-1:12345678910:function:test",
- "lambda_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72",
+ "function_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72",
"correlation_id": "correlation_id_value"
}
```
@@ -510,7 +510,7 @@ this means that custom keys can be persisted across invocations. If you want all
"functionName": "test",
"functionMemorySize": 128,
"functionArn": "arn:aws:lambda:eu-west-1:12345678910:function:test",
- "lambda_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72",
+ "function_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72",
"specialKey": "value"
}
```
@@ -527,7 +527,7 @@ this means that custom keys can be persisted across invocations. If you want all
"functionName": "test",
"functionMemorySize": 128,
"functionArn": "arn:aws:lambda:eu-west-1:12345678910:function:test",
- "lambda_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72"
+ "function_request_id": "52fdfc07-2182-154f-163f-5f0f9a621d72"
}
```
diff --git a/docs/stylesheets/extra.css b/docs/stylesheets/extra.css
index de2f3b5f9..d135d7210 100644
--- a/docs/stylesheets/extra.css
+++ b/docs/stylesheets/extra.css
@@ -3,7 +3,9 @@
}
.highlight .hll {
- background-color: lavender
+ [data-md-color-scheme="default"] {
+ background-color: lavender;
+ }
}
.md-typeset table:not([class]) {
diff --git a/examples/README.md b/examples/README.md
index 79e2133ad..52dc0c1e9 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -5,9 +5,10 @@ Each example can be copied from its subdirectory and used independently of the r
## Examples
-* [powertools-examples-core-utilities](powertools-examples-core-utilities) - Demonstrates the core logging, tracing, and metrics modules with different build tools
- * [SAM](powertools-examples-core-utilities/sam)
- * [CDK](powertools-examples-core-utilities/cdk)
+* [powertools-examples-core](powertools-examples-core) - Demonstrates the core logging, tracing, and metrics modules with different build tools
+ * [SAM](./powertools-examples-core/sam)
+ * [CDK](./powertools-examples-core/cdk)
+ * [Serverless](./powertools-examples-core/serverless)
* [powertools-examples-idempotency](powertools-examples-idempotency) - An idempotent HTTP API
* [powertools-examples-parameters](powertools-examples-parameters) - Uses the parameters module to provide runtime parameters to a function
* [powertools-examples-serialization](powertools-examples-serialization) - Uses the serialization module to serialize and deserialize API Gateway & SQS payloads
@@ -54,7 +55,7 @@ The first command will build the source of your application. The second command
You can find your API Gateway Endpoint URL in the output values displayed after deployment.
-If you're not using SAM, you can look for examples for other tools under [powertools-examples-core-utilities](./powertools-examples-core-utilities)
+If you're not using SAM, you can look for examples for other tools under [powertools-examples-core](./powertools-examples-core)
### External examples
diff --git a/examples/pom.xml b/examples/pom.xml
index da6e272de..be52778da 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -32,6 +32,7 @@
powertools-examples-core-utilities/sam
powertools-examples-core-utilities/cdk/app
powertools-examples-core-utilities/cdk/infra
+ powertools-examples-core-utilities/serverless
powertools-examples-idempotency
powertools-examples-parameters
powertools-examples-serialization
diff --git a/examples/powertools-examples-batch/pom.xml b/examples/powertools-examples-batch/pom.xml
index 8d2c6052a..1387cca6d 100644
--- a/examples/powertools-examples-batch/pom.xml
+++ b/examples/powertools-examples-batch/pom.xml
@@ -14,8 +14,9 @@
2.20.0
1.8
1.8
- 2.20.133
+ 2.20.162
1.9.20
+
diff --git a/examples/powertools-examples-cloudformation/pom.xml b/examples/powertools-examples-cloudformation/pom.xml
index c8eff3211..cc95a2dfc 100644
--- a/examples/powertools-examples-cloudformation/pom.xml
+++ b/examples/powertools-examples-cloudformation/pom.xml
@@ -14,9 +14,10 @@
1.8
1.8
1.2.3
- 3.11.2
- 2.20.136
+ 3.11.3
+ 2.20.162
1.9.20
+
diff --git a/examples/powertools-examples-core-utilities/README.md b/examples/powertools-examples-core-utilities/README.md
index 6960bb1f5..1d1dd031f 100644
--- a/examples/powertools-examples-core-utilities/README.md
+++ b/examples/powertools-examples-core-utilities/README.md
@@ -9,10 +9,11 @@ We provide examples for the following infrastructure-as-code tools:
* [AWS SAM](sam/)
* [AWS CDK](cdk/)
+* [Serverless framework](serverless/)
We also provide an example showing the integration of SAM, Powertools, and Gradle:
-* [AWS SAM with a Gradle build](../powertools-examples-core-utilities/gradle/)
+* [AWS SAM with a Gradle build](gradle/)
For each of the tools, the example application is the same, and consists of the following files:
diff --git a/examples/powertools-examples-core-utilities/cdk/README.md b/examples/powertools-examples-core-utilities/cdk/README.md
index acd857ed7..f15a24168 100644
--- a/examples/powertools-examples-core-utilities/cdk/README.md
+++ b/examples/powertools-examples-core-utilities/cdk/README.md
@@ -6,11 +6,11 @@ For general information on the deployed example itself, you can refer to the par
## Configuration
CDK uses the following project structure:
-- [app](app) - stores the source code of your application, which is similar between all examples
-- [infra](infra) - stores the definition of your infrastructure
- - [cdk.json](infra/cdk.json) - tells the CDK Toolkit how to execute your app
- - [CdkApp](infra/src/main/java/cdk/CdkApp.java) - bootstraps your stack, taking AWS `account` and `region` as input
- - [CdkStack](infra/src/main/java/cdk/CdkStack.java) - defines the Lambda function to be deployed as well as API Gateway for it.
+- [app](./app) - stores the source code of your application, which is similar between all examples
+- [infra](./infra) - stores the definition of your infrastructure
+ - [cdk.json](./infra/cdk.json) - tells the CDK Toolkit how to execute your app
+ - [CdkApp](./infra/src/main/java/cdk/CdkApp.java) - bootstraps your stack, taking AWS `account` and `region` as input
+ - [CdkStack](./infra/src/main/java/cdk/CdkStack.java) - defines the Lambda function to be deployed as well as API Gateway for it.
It is a [Maven](https://maven.apache.org/) based project, so you can open this project with any Maven compatible Java IDE to build and run tests.
diff --git a/examples/powertools-examples-core-utilities/cdk/app/pom.xml b/examples/powertools-examples-core-utilities/cdk/app/pom.xml
index 51c222a07..891a7c7f6 100644
--- a/examples/powertools-examples-core-utilities/cdk/app/pom.xml
+++ b/examples/powertools-examples-core-utilities/cdk/app/pom.xml
@@ -3,11 +3,12 @@
4.0.0
software.amazon.lambda.examples
+
1.17.0
powertools-examples-core-utilities-cdk
jar
-
- Powertools for AWS Lambda (Java) library Examples - Core Utilities (logging, tracing, metrics) with CDK
+ Powertools for AWS Lambda (Java) library Examples - Core
2.20.0
@@ -40,7 +41,7 @@
com.amazonaws
aws-lambda-java-events
- 3.11.2
+ 3.11.3
org.apache.logging.log4j
@@ -119,7 +120,8 @@
-
+
diff --git a/examples/powertools-examples-core-utilities/gradle/README.md b/examples/powertools-examples-core-utilities/gradle/README.md
index cd6107151..c7c798d5d 100644
--- a/examples/powertools-examples-core-utilities/gradle/README.md
+++ b/examples/powertools-examples-core-utilities/gradle/README.md
@@ -8,7 +8,7 @@ You can also use `sam init` to create a new Gradle-powered Powertools applicatio
and then **Hello World Example with Powertools for AWS Lambda**, **Java 17** runtime, and finally **gradle**.
-For general information on the deployed example itself, you can refer to the parent [README](../../powertools-examples-core/README.md)
+For general information on the deployed example itself, you can refer to the parent [README](../README.md)
## Configuration
SAM uses [template.yaml](template.yaml) to define the application's AWS resources.
diff --git a/examples/powertools-examples-core-utilities/sam/pom.xml b/examples/powertools-examples-core-utilities/sam/pom.xml
index 55b06cbf7..130fb814d 100644
--- a/examples/powertools-examples-core-utilities/sam/pom.xml
+++ b/examples/powertools-examples-core-utilities/sam/pom.xml
@@ -1,13 +1,12 @@
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
+ Powertools for AWS Lambda (Java) library Examples - Core Utilities (logging, tracing, metrics) with SAM
software.amazon.lambda.examples
2.0.0-SNAPSHOT
powertools-examples-core-utilities-sam
jar
-
- Powertools for AWS Lambda (Java) library Examples - Core Utilities (logging, tracing, metrics) with SAM
2.20.0
@@ -40,7 +39,7 @@
com.amazonaws
aws-lambda-java-events
- 3.11.2
+ 3.11.3
org.apache.logging.log4j
diff --git a/examples/powertools-examples-core-utilities/serverless/README.md b/examples/powertools-examples-core-utilities/serverless/README.md
new file mode 100644
index 000000000..aec093182
--- /dev/null
+++ b/examples/powertools-examples-core-utilities/serverless/README.md
@@ -0,0 +1,26 @@
+# Powertools for AWS Lambda (Java) - Core Utilities Example with Serverless Framework
+
+This project demonstrates the Lambda for Powertools Java module deployed using [Serverless Framework](https://www.serverless.com/framework).
+For general information on the deployed example itself, you can refer to the parent [README](../README.md).
+To install Serverless Framework if you don't have it yet, you can follow the [Getting Started Guide](https://www.serverless.com/framework/docs/getting-started).
+
+## Configuration
+Serverless Framework uses [serverless.yml](./serverless.yml) to define the application's AWS resources.
+This file defines the Lambda function to be deployed as well as API Gateway for it.
+
+It is a [Maven](https://maven.apache.org/) based project, so you can open this project with any Maven compatible Java IDE to build and run tests.
+
+
+## Deploy the sample application
+
+To deploy the app, simply run the following commands:
+```bash
+mvn package && sls deploy
+```
+
+## Useful commands
+
+Deploy a single function
+```bash
+sls deploy function -f hello
+```
\ No newline at end of file
diff --git a/examples/powertools-examples-core-utilities/serverless/pom.xml b/examples/powertools-examples-core-utilities/serverless/pom.xml
new file mode 100644
index 000000000..013f8bd7d
--- /dev/null
+++ b/examples/powertools-examples-core-utilities/serverless/pom.xml
@@ -0,0 +1,155 @@
+
+ 4.0.0
+
+ Powertools for AWS Lambda (Java) library Examples - Core Utilities (logging, tracing, metrics) with SAM
+ software.amazon.lambda.examples
+ 2.0.0-SNAPSHOT
+ powertools-examples-core-utilities-serverless
+ jar
+
+
+ 2.20.0
+ 1.8
+ 1.8
+ 1.9.20
+
+
+
+
+ software.amazon.lambda
+ powertools-tracing
+ ${project.version}
+
+
+ software.amazon.lambda
+ powertools-logging
+ ${project.version}
+
+
+ software.amazon.lambda
+ powertools-metrics
+ ${project.version}
+
+
+ com.amazonaws
+ aws-lambda-java-core
+ 1.2.3
+
+
+ com.amazonaws
+ aws-lambda-java-events
+ 3.11.3
+
+
+ org.apache.logging.log4j
+ log4j-core
+ ${log4j.version}
+
+
+ org.apache.logging.log4j
+ log4j-api
+ ${log4j.version}
+
+
+ org.aspectj
+ aspectjrt
+ ${aspectj.version}
+
+
+
+ junit
+ junit
+ 4.13.2
+ test
+
+
+
+
+
+
+ dev.aspectj
+ aspectj-maven-plugin
+ 1.13.1
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+ ${maven.compiler.target}
+
+
+ software.amazon.lambda
+ powertools-tracing
+
+
+ software.amazon.lambda
+ powertools-logging
+
+
+ software.amazon.lambda
+ powertools-metrics
+
+
+
+
+
+
+ compile
+
+
+
+
+
+ org.aspectj
+ aspectjtools
+ ${aspectj.version}
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.5.0
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
+
+
+
+ org.apache.logging.log4j
+ log4j-transform-maven-shade-plugin-extensions
+ 0.1.0
+
+
+
+
+
+
+
+
+ jdk8
+
+ (,11)
+
+
+ 1.9.7
+
+
+
+
diff --git a/examples/powertools-examples-core-utilities/serverless/serverless.yml b/examples/powertools-examples-core-utilities/serverless/serverless.yml
new file mode 100644
index 000000000..d8dec8080
--- /dev/null
+++ b/examples/powertools-examples-core-utilities/serverless/serverless.yml
@@ -0,0 +1,40 @@
+service: hello
+# app and org for use with dashboard.serverless.com
+#app: your-app-name
+#org: your-org-name
+
+# You can pin your service to only deploy with a specific Serverless version
+# Check out our docs for more details
+frameworkVersion: '3'
+
+provider:
+ name: aws
+ runtime: java11
+
+# you can overwrite defaults here
+# stage: dev
+# region: us-east-1
+
+# you can define service wide environment variables here
+ environment:
+ POWERTOOLS_LOG_LEVEL: INFO
+ POWERTOOLS_LOGGER_SAMPLE_RATE: 0.1
+ POWERTOOLS_METRICS_NAMESPACE: Coreutilities
+
+# you can add packaging information here
+package:
+ artifact: target/helloworld-lambda.jar
+
+functions:
+ hello:
+ handler: helloworld.App
+ memorySize: 512
+ timeout: 20
+ tracing: "Active"
+ events:
+ - httpApi:
+ path: /hello
+ method: get
+# Define function environment variables here
+ environment:
+ POWERTOOLS_SERVICE_NAME: hello
diff --git a/examples/powertools-examples-core-utilities/serverless/src/main/java/helloworld/App.java b/examples/powertools-examples-core-utilities/serverless/src/main/java/helloworld/App.java
new file mode 100644
index 000000000..c89545fc9
--- /dev/null
+++ b/examples/powertools-examples-core-utilities/serverless/src/main/java/helloworld/App.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2023 Amazon.com, Inc. or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package helloworld;
+
+import static software.amazon.lambda.powertools.metrics.MetricsUtils.metricsLogger;
+import static software.amazon.lambda.powertools.metrics.MetricsUtils.withSingleMetric;
+import static software.amazon.lambda.powertools.tracing.TracingUtils.putMetadata;
+
+import com.amazonaws.services.lambda.runtime.Context;
+import com.amazonaws.services.lambda.runtime.RequestHandler;
+import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
+import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import software.amazon.cloudwatchlogs.emf.model.DimensionSet;
+import software.amazon.cloudwatchlogs.emf.model.Unit;
+import software.amazon.lambda.powertools.logging.Logging;
+import software.amazon.lambda.powertools.logging.LoggingUtils;
+import software.amazon.lambda.powertools.metrics.Metrics;
+import software.amazon.lambda.powertools.tracing.CaptureMode;
+import software.amazon.lambda.powertools.tracing.Tracing;
+import software.amazon.lambda.powertools.tracing.TracingUtils;
+
+/**
+ * Handler for requests to Lambda function.
+ */
+public class App implements RequestHandler {
+ private final static Logger log = LogManager.getLogger(App.class);
+ @Tracing(captureMode = CaptureMode.RESPONSE_AND_ERROR)
+ public APIGatewayProxyResponseEvent handleRequest(final APIGatewayProxyRequestEvent input, final Context context) {
+ Map headers = new HashMap<>();
+
+ headers.put("Content-Type", "application/json");
+ headers.put("X-Custom-Header", "application/json");
+
+ metricsLogger().putMetric("CustomMetric1", 1, Unit.COUNT);
+
+ withSingleMetric("CustomMetrics2", 1, Unit.COUNT, "Another", (metric) ->
+ {
+ metric.setDimensions(DimensionSet.of("AnotherService", "CustomService"));
+ metric.setDimensions(DimensionSet.of("AnotherService1", "CustomService1"));
+ });
+
+ LoggingUtils.appendKey("test", "willBeLogged");
+
+ APIGatewayProxyResponseEvent response = new APIGatewayProxyResponseEvent()
+ .withHeaders(headers);
+ try {
+ final String pageContents = this.getPageContents("https://checkip.amazonaws.com");
+ log.info(pageContents);
+ TracingUtils.putAnnotation("Test", "New");
+ String output = String.format("{ \"message\": \"hello world\", \"location\": \"%s\" }", pageContents);
+
+ TracingUtils.withSubsegment("loggingResponse", subsegment ->
+ {
+ String sampled = "log something out";
+ log.info(sampled);
+ log.info(output);
+ });
+
+ log.info("After output");
+ return response
+ .withStatusCode(200)
+ .withBody(output);
+ } catch (RuntimeException | IOException e) {
+ return response
+ .withBody("{}")
+ .withStatusCode(500);
+ }
+ }
+
+ @Tracing(namespace = "getPageContents", captureMode = CaptureMode.DISABLED)
+ private String getPageContents(String address) throws IOException {
+ URL url = new URL(address);
+ putMetadata("getPageContents", address);
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()))) {
+ return br.lines().collect(Collectors.joining(System.lineSeparator()));
+ }
+ }
+}
diff --git a/examples/powertools-examples-core-utilities/serverless/src/main/java/helloworld/AppStream.java b/examples/powertools-examples-core-utilities/serverless/src/main/java/helloworld/AppStream.java
new file mode 100644
index 000000000..401ef8c48
--- /dev/null
+++ b/examples/powertools-examples-core-utilities/serverless/src/main/java/helloworld/AppStream.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2023 Amazon.com, Inc. or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package helloworld;
+
+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 software.amazon.lambda.powertools.logging.Logging;
+import software.amazon.lambda.powertools.metrics.Metrics;
+
+public class AppStream implements RequestStreamHandler {
+ private static final ObjectMapper mapper = new ObjectMapper();
+
+ @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);
+
+ System.out.println(map.size());
+ }
+}
diff --git a/examples/powertools-examples-core-utilities/serverless/src/main/resources/log4j2.xml b/examples/powertools-examples-core-utilities/serverless/src/main/resources/log4j2.xml
new file mode 100644
index 000000000..0cc0953f0
--- /dev/null
+++ b/examples/powertools-examples-core-utilities/serverless/src/main/resources/log4j2.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/examples/powertools-examples-core-utilities/serverless/src/test/java/helloworld/AppTest.java b/examples/powertools-examples-core-utilities/serverless/src/test/java/helloworld/AppTest.java
new file mode 100644
index 000000000..70dad8d71
--- /dev/null
+++ b/examples/powertools-examples-core-utilities/serverless/src/test/java/helloworld/AppTest.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2023 Amazon.com, Inc. or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package helloworld;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
+import com.amazonaws.xray.AWSXRay;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AppTest {
+
+ @Before
+ public void setup() {
+ if (null == System.getenv("LAMBDA_TASK_ROOT")) {
+ AWSXRay.beginSegment("test");
+ }
+ }
+
+ @After
+ public void tearDown() {
+ if (AWSXRay.getCurrentSubsegmentOptional().isPresent()) {
+ AWSXRay.endSubsegment();
+ }
+
+ if (null == System.getenv("LAMBDA_TASK_ROOT")) {
+ AWSXRay.endSegment();
+ }
+ }
+
+ @Test
+ public void successfulResponse() {
+ App app = new App();
+ APIGatewayProxyResponseEvent result = app.handleRequest(null, null);
+ assertEquals(result.getStatusCode().intValue(), 200);
+ assertEquals(result.getHeaders().get("Content-Type"), "application/json");
+ String content = result.getBody();
+ assertNotNull(content);
+ assertTrue(content.contains("\"message\""));
+ assertTrue(content.contains("\"hello world\""));
+ assertTrue(content.contains("\"location\""));
+ }
+}
diff --git a/examples/powertools-examples-idempotency/pom.xml b/examples/powertools-examples-idempotency/pom.xml
index c28594023..02fca7e98 100644
--- a/examples/powertools-examples-idempotency/pom.xml
+++ b/examples/powertools-examples-idempotency/pom.xml
@@ -53,7 +53,7 @@
com.amazonaws
aws-lambda-java-events
- 3.11.2
+ 3.11.3
org.apache.logging.log4j
@@ -97,104 +97,111 @@
-
-
- dev.aspectj
- aspectj-maven-plugin
- 1.13.1
-
- ${maven.compiler.source}
- ${maven.compiler.target}
- ${maven.compiler.target}
-
-
- software.amazon.lambda
- powertools-tracing
-
-
- software.amazon.lambda
- powertools-logging
-
-
- software.amazon.lambda
- powertools-idempotency
-
-
-
-
-
-
- compile
-
-
-
-
-
- org.aspectj
- aspectjtools
- ${aspectj.version}
-
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
- copy
- test-compile
-
- copy-dependencies
-
-
- test
- so,dll,dylib
- ${project.build.directory}/native-libs
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- 3.1.2
-
-
- ${project.build.directory}/native-libs
-
-
- idempotency
- eu-central-1
- LOG_ERROR
-
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- 3.5.0
-
-
- package
-
- shade
-
-
-
-
-
-
-
-
-
-
- org.apache.logging.log4j
- log4j-transform-maven-shade-plugin-extensions
- 0.1.0
-
-
-
-
+
+
+ dev.aspectj
+ aspectj-maven-plugin
+ 1.13.1
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+ ${maven.compiler.target}
+
+
+ software.amazon.lambda
+ powertools-tracing
+
+
+ software.amazon.lambda
+ powertools-logging
+
+
+ software.amazon.lambda
+ powertools-idempotency
+
+
+
+
+
+
+ compile
+
+
+
+
+
+ org.aspectj
+ aspectjtools
+ ${aspectj.version}
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy
+ test-compile
+
+ copy-dependencies
+
+
+ test
+ so,dll,dylib
+ ${project.build.directory}/native-libs
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.1.2
+
+
+ ${project.build.directory}/native-libs
+
+
+ idempotency
+ eu-central-1
+ LOG_ERROR
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.5.0
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
+
+
+
+ org.apache.logging.log4j
+ log4j-transform-maven-shade-plugin-extensions
+ 0.1.0
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ true
+
+
+
- 3.1.2
-
-
- dev.aspectj
- aspectj-maven-plugin
- 1.13.1
-
- ${maven.compiler.source}
- ${maven.compiler.target}
- ${maven.compiler.target}
-
-
- software.amazon.lambda
- powertools-parameters
-
-
-
-
-
-
- compile
-
-
-
-
-
- org.aspectj
- aspectjtools
- ${aspectj.version}
-
-
-
-
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ 3.1.2
+
+
+ dev.aspectj
+ aspectj-maven-plugin
+ 1.13.1
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+ ${maven.compiler.target}
+
+
+ software.amazon.lambda
+ powertools-parameters
+
+
+
+
+
+
+ compile
+
+
+
+
+
+ org.aspectj
+ aspectjtools
+ ${aspectj.version}
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ true
+
+
+
@@ -71,6 +71,14 @@
true
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+ true
+
+
dev.aspectj
aspectj-maven-plugin
diff --git a/examples/powertools-examples-validation/pom.xml b/examples/powertools-examples-validation/pom.xml
index 08d2eba32..679e698e9 100644
--- a/examples/powertools-examples-validation/pom.xml
+++ b/examples/powertools-examples-validation/pom.xml
@@ -71,44 +71,44 @@
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
- 3.1.2
-
-
- dev.aspectj
- aspectj-maven-plugin
- 1.13.1
-
- ${maven.compiler.source}
- ${maven.compiler.target}
- ${maven.compiler.target}
-
-
- software.amazon.lambda
- powertools-validation
-
-
-
-
-
-
- compile
-
-
-
-
-
- org.aspectj
- aspectjtools
- ${aspectj.version}
-
-
-
-
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ 3.1.2
+
+
+ dev.aspectj
+ aspectj-maven-plugin
+ 1.13.1
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+ ${maven.compiler.target}
+
+
+ software.amazon.lambda
+ powertools-validation
+
+
+
+
+
+
+ compile
+
+
+
+
+
+ org.aspectj
+ aspectjtools
+ ${aspectj.version}
+
+
+
+