Skip to content

Commit 77f916a

Browse files
committed
Merge missing changes
2 parents 26730af + 8e4173a commit 77f916a

File tree

7 files changed

+124
-54
lines changed

7 files changed

+124
-54
lines changed

README.md

+29-10
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,11 @@ Powertools for AWS Lambda (Java) is a developer toolkit to implement Serverless
1111
1212
**[📜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/)**
1313

14-
### Java Compatibility
15-
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
16-
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
17-
18-
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).
19-
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
20-
Lambda runtimes.
21-
22-
### Installation
14+
## Installation
2315

2416
Powertools for AWS Lambda (Java) is available in Maven Central. You can use your favourite dependency management tool to install it
2517

26-
#### Maven:
18+
### Maven:
2719
```xml
2820
<dependencies>
2921
...
@@ -198,6 +190,33 @@ Next, configure the aspectj-maven-plugin to compile-time weave (CTW) the aws-lam
198190
```
199191
</details>
200192

193+
### Java Compatibility
194+
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
195+
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
196+
For the modules that provide annotations, Powertools for AWS Lambda (Java) leverages the **aspectj** library.
197+
You may need to add the good version of `aspectjrt` to your dependencies based on the JDK used for building your function:
198+
199+
```xml
200+
<dependency>
201+
<groupId>org.aspectj</groupId>
202+
<artifactId>aspectjrt</artifactId>
203+
<version>1.9.??</version>
204+
</dependency>
205+
```
206+
207+
<details>
208+
<summary><b>JDK - aspectj dependency matrix</b></summary>
209+
210+
| JDK version | aspectj version |
211+
|-------------|-----------------|
212+
| `1.8` | `1.9.7` |
213+
| `11-17` | `1.9.20.1` |
214+
| `21` | `1.9.21` |
215+
216+
More info [here](https://github.com/aws-powertools/powertools-lambda-java/pull/1519/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R191).
217+
218+
</details>
219+
201220
## Examples
202221

203222
See the latest release of the **[examples](https://github.com/aws-powertools/powertools-lambda-java/tree/v1.18.0/examples)** for example projects showcasing usage of different utilities.

docs/core/logging.md

+20-14
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,18 @@ via `samplingRate` attribute on annotation.
596596
POWERTOOLS_LOGGER_SAMPLE_RATE: 0.5
597597
```
598598

599-
## AWS Lambda Advanced Logging Controls
600-
With AWS [Lambda Advanced Logging Controls (ALC)](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced), you can control the output format of your logs as either `TEXT` or `JSON` and specify the minimum accepted log level for your application.
601-
Regardless of the output format setting in Lambda, Powertools for AWS Lambda will always output JSON formatted logging messages.
599+
## AWS Lambda Advanced Logging Controls (ALC)
602600

603-
When you have this feature enabled, log messages that don’t meet the configured log level are discarded by Lambda.
604-
For example, if you set the minimum log level to `WARN`, you will only receive `WARN` and `ERROR` messages in your AWS CloudWatch Logs, all other log levels will be discarded by Lambda.
601+
!!!question "When is it useful?"
602+
When you want to set a logging policy to drop informational or verbose logs for one or all AWS Lambda functions, regardless of runtime and logger used.
603+
604+
<!-- markdownlint-disable MD013 -->
605+
With [AWS Lambda Advanced Logging Controls (ALC)](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-advanced){target="_blank"}, you can enforce a minimum log level that Lambda will accept from your application code.
606+
607+
When enabled, you should keep `Logger` and ALC log level in sync to avoid data loss.
608+
609+
Here's a sequence diagram to demonstrate how ALC will drop both `INFO` and `DEBUG` logs emitted from `Logger`, when ALC log level is stricter than `Logger`.
610+
<!-- markdownlint-enable MD013 -->
605611

606612
```mermaid
607613
sequenceDiagram
@@ -610,29 +616,29 @@ sequenceDiagram
610616
participant Application Logger
611617
612618
Note over Lambda service: AWS_LAMBDA_LOG_LEVEL="WARN"
619+
Note over Application Logger: POWERTOOLS_LOG_LEVEL="DEBUG"
620+
613621
Lambda service->>Lambda function: Invoke (event)
614622
Lambda function->>Lambda function: Calls handler
615-
Lambda function->>Application Logger: logger.warn("Something happened")
623+
Lambda function->>Application Logger: logger.error("Something happened")
616624
Lambda function-->>Application Logger: logger.debug("Something happened")
617625
Lambda function-->>Application Logger: logger.info("Something happened")
618-
619-
Lambda service->>Lambda service: DROP INFO and DEBUG logs
620-
626+
Lambda service--xLambda service: DROP INFO and DEBUG logs
621627
Lambda service->>CloudWatch Logs: Ingest error logs
622628
```
623629

624-
Logger will automatically listen for the `AWS_LAMBDA_LOG_FORMAT` and `AWS_LAMBDA_LOG_LEVEL` environment variables, and change behaviour if they’re found to ensure as much compatibility as possible.
625-
626630
### Priority of log level settings in Powertools for AWS Lambda
627631

628-
When the Advanced Logging Controls feature is enabled, we are unable to increase the minimum log level below the `AWS_LAMBDA_LOG_LEVEL` environment variable value, see [AWS Lambda service documentation](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-log-level) for more details.
629-
630632
We prioritise log level settings in this order:
631633

632634
1. `AWS_LAMBDA_LOG_LEVEL` environment variable
633635
2. `POWERTOOLS_LOG_LEVEL` environment variable
634636

635-
In the event you have set `POWERTOOLS_LOG_LEVEL` to a level lower than the ACL setting, Powertools for AWS Lambda will output a warning log message informing you that your messages will be discarded by Lambda.
637+
If you set `Logger` level lower than ALC, we will emit a warning informing you that your messages will be discarded by Lambda.
638+
639+
> **NOTE**
640+
>
641+
> With ALC enabled, we are unable to increase the minimum log level below the `AWS_LAMBDA_LOG_LEVEL` environment variable value, see [AWS Lambda service documentation](https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html#monitoring-cloudwatchlogs-log-level){target="_blank"} for more details.
636642
637643
### Timestamp format
638644

docs/index.md

+35-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ Powertools for AWS Lambda (Java) is a suite of utilities for AWS Lambda Function
1515
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,
1616
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.
1717

18-
???+ tip "Java Compatability"
19-
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
20-
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
21-
22-
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).
23-
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
24-
Lambda runtimes.
25-
2618
## Tenets
2719

2820
This project separates core utilities that will be available in other runtimes vs general utilities that might not be available across all runtimes.
@@ -282,6 +274,41 @@ Depending on your version of Java (either Java 1.8 or 11+), the configuration sl
282274
Under the hood, `org.codehaus.mojo:aspectj-maven-plugin` is based on AspectJ 1.9.7,
283275
while `dev.aspectj:aspectj-maven-plugin` is based on AspectJ 1.9.8, compiled for Java 11+.
284276

277+
### Java Compatibility
278+
Powertools for AWS Lambda (Java) supports all Java version from 8 up to 21 as well as the
279+
[corresponding Lambda runtimes](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html).
280+
281+
For the following modules, Powertools for AWS Lambda (Java) leverages the **aspectj** library to provide annotations:
282+
- Logging
283+
- Metrics
284+
- Tracing
285+
- Parameters
286+
- Idempotency
287+
- Validation
288+
- Large messages
289+
290+
291+
You may need to add the good version of `aspectjrt` to your dependencies based on the jdk used for building your function:
292+
293+
```xml
294+
<dependency>
295+
<groupId>org.aspectj</groupId>
296+
<artifactId>aspectjrt</artifactId>
297+
<version>1.9.??</version>
298+
</dependency>
299+
```
300+
301+
Use the following [dependency matrix](https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md) between this library and the JDK:
302+
303+
| JDK version | aspectj version |
304+
|-------------|-----------------|
305+
| `1.8` | `1.9.7` |
306+
| `11-17` | `1.9.20.1` |
307+
| `21` | `1.9.21` |
308+
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+
285312
## Environment variables
286313

287314
!!! info

pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
<maven.compiler.target>1.8</maven.compiler.target>
7474
<log4j.version>2.20.0</log4j.version>
7575
<jackson.version>2.15.3</jackson.version>
76-
<aspectj.version>1.9.7</aspectj.version>
7776
<aws.sdk.version>2.21.0</aws.sdk.version>
7877
<aws.xray.recorder.version>2.14.0</aws.xray.recorder.version>
7978
<payloadoffloading-common.version>2.1.3</payloadoffloading-common.version>
@@ -82,6 +81,7 @@
8281
<lambda.events.version>3.11.2</lambda.events.version>
8382
<lambda.serial.version>1.1.2</lambda.serial.version>
8483
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
84+
<aspectj.version>1.9.7</aspectj.version>
8585
<aspectj-maven-plugin.version>1.13.1</aspectj-maven-plugin.version>
8686
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
8787
<jacoco-maven-plugin.version>0.8.10</jacoco-maven-plugin.version>
@@ -514,6 +514,7 @@
514514
</plugins>
515515
</build>
516516
</profile>
517+
517518
<profile>
518519
<id>jdk16</id>
519520
<activation>

powertools-e2e-tests/handlers/logging/pom.xml

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
<groupId>software.amazon.lambda</groupId>
1818
<artifactId>powertools-logging</artifactId>
1919
</dependency>
20+
<dependency>
21+
<groupId>org.aspectj</groupId>
22+
<artifactId>aspectjrt</artifactId>
23+
</dependency>
2024
<dependency>
2125
<groupId>com.amazonaws</groupId>
2226
<artifactId>aws-lambda-java-events</artifactId>

powertools-e2e-tests/handlers/pom.xml

+32-14
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343
<type>pom</type>
4444
<scope>import</scope>
4545
</dependency>
46-
46+
<dependency>
47+
<groupId>org.aspectj</groupId>
48+
<artifactId>aspectjrt</artifactId>
49+
<version>${aspectj.version}</version>
50+
</dependency>
4751
<dependency>
4852
<groupId>software.amazon.lambda</groupId>
4953
<artifactId>powertools-logging</artifactId>
@@ -99,11 +103,6 @@
99103
<artifactId>log4j-slf4j2-impl</artifactId>
100104
<version>${log4j.version}</version>
101105
</dependency>
102-
<dependency>
103-
<groupId>org.aspectj</groupId>
104-
<artifactId>aspectjrt</artifactId>
105-
<version>${aspectj.version}</version>
106-
</dependency>
107106
</dependencies>
108107
</dependencyManagement>
109108

@@ -132,11 +131,11 @@
132131
</execution>
133132
</executions>
134133
<dependencies>
135-
<dependency>
136-
<groupId>org.apache.logging.log4j</groupId>
137-
<artifactId>log4j-transform-maven-shade-plugin-extensions</artifactId>
138-
<version>0.1.0</version>
139-
</dependency>
134+
<dependency>
135+
<groupId>org.apache.logging.log4j</groupId>
136+
<artifactId>log4j-transform-maven-shade-plugin-extensions</artifactId>
137+
<version>0.1.0</version>
138+
</dependency>
140139
</dependencies>
141140
</plugin>
142141
<plugin>
@@ -154,6 +153,7 @@
154153
<artifactId>aspectj-maven-plugin</artifactId>
155154
<version>${aspectj.plugin.version}</version>
156155
<configuration>
156+
<verbose>true</verbose>
157157
<source>${maven.compiler.source}</source>
158158
<target>${maven.compiler.target}</target>
159159
<complianceLevel>${maven.compiler.target}</complianceLevel>
@@ -162,7 +162,6 @@
162162
</configuration>
163163
<executions>
164164
<execution>
165-
<phase>process-sources</phase>
166165
<goals>
167166
<goal>compile</goal>
168167
<goal>test-compile</goal>
@@ -182,15 +181,34 @@
182181
</build>
183182

184183
<profiles>
184+
<!-- https://github.com/eclipse-aspectj/aspectj/blob/master/docs/dist/doc/JavaVersionCompatibility.md -->
185185
<profile>
186-
<id>jdk8</id>
186+
<id>jdk8to16</id>
187187
<activation>
188-
<jdk>(,11)</jdk> <!-- < 11 -->
188+
<jdk>[1.8,16]</jdk>
189189
</activation>
190190
<properties>
191191
<aspectj.version>1.9.7</aspectj.version>
192192
</properties>
193193
</profile>
194+
<profile>
195+
<id>jdk17to20</id>
196+
<activation>
197+
<jdk>[17,20]</jdk>
198+
</activation>
199+
<properties>
200+
<aspectj.version>1.9.20.1</aspectj.version>
201+
</properties>
202+
</profile>
203+
<profile>
204+
<id>jdk21</id>
205+
<activation>
206+
<jdk>[21,)</jdk>
207+
</activation>
208+
<properties>
209+
<aspectj.version>1.9.21.M1</aspectj.version>
210+
</properties>
211+
</profile>
194212
</profiles>
195213

196214
</project>

powertools-e2e-tests/src/test/java/software/amazon/lambda/powertools/testutils/Infrastructure.java

+2-7
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ public class Infrastructure {
114114
private final String queue;
115115
private final String kinesisStream;
116116
private final String largeMessagesBucket;
117-
private final JavaRuntime lambdaRuntimeVersion;
118117
private String ddbStreamsTableName;
119118
private String functionName;
120119
private Object cfnTemplate;
@@ -125,7 +124,6 @@ private Infrastructure(Builder builder) {
125124
this.tracing = builder.tracing;
126125
this.envVar = builder.environmentVariables;
127126
this.runtime = builder.runtime;
128-
this.lambdaRuntimeVersion = builder.lambdaRuntimeVersion;
129127
this.timeout = builder.timeoutInSeconds;
130128
this.pathToFunction = builder.pathToFunction;
131129
this.idempotencyTable = builder.idemPotencyTable;
@@ -213,7 +211,6 @@ private Stack createStackWithLambda() {
213211
"cd " + pathToFunction +
214212
" && timeout -s SIGKILL 5m mvn clean install -ff " +
215213
" -Dmaven.test.skip=true " +
216-
" -Dmaven.resources.skip=true " +
217214
" -Dmaven.compiler.source=" + runtime.getMvnProperty() +
218215
" -Dmaven.compiler.target=" + runtime.getMvnProperty() +
219216
" && cp /asset-input/" + pathToFunction + "/target/function.jar /asset-output/"
@@ -250,7 +247,7 @@ private Stack createStackWithLambda() {
250247
.handler("software.amazon.lambda.powertools.e2e.Function::handleRequest")
251248
.memorySize(1024)
252249
.timeout(Duration.seconds(timeout))
253-
.runtime(lambdaRuntimeVersion.getCdkRuntime())
250+
.runtime(runtime.getCdkRuntime())
254251
.environment(envVar)
255252
.tracing(tracing ? Tracing.ACTIVE : Tracing.DISABLED)
256253
.build();
@@ -507,11 +504,9 @@ public static class Builder {
507504
private String queue;
508505
private String kinesisStream;
509506
private String ddbStreamsTableName;
510-
private JavaRuntime lambdaRuntimeVersion;
511507

512508
private Builder() {
513509
runtime = mapRuntimeVersion("JAVA_VERSION");
514-
lambdaRuntimeVersion = mapRuntimeVersion("JAVA_LAMBDA_RUNTIME_VERSION");
515510
}
516511

517512

@@ -520,7 +515,7 @@ private JavaRuntime mapRuntimeVersion(String environmentVariableName) {
520515
String javaVersion = System.getenv(environmentVariableName); // must be set in GitHub actions
521516
JavaRuntime ret = null;
522517
if (javaVersion == null) {
523-
throw new IllegalArgumentException("JAVA_LAMBDA_RUNTIME_VERSION is not set");
518+
throw new IllegalArgumentException(environmentVariableName + " is not set");
524519
}
525520
if (javaVersion.startsWith("8")) {
526521
ret = JavaRuntime.JAVA8AL2;

0 commit comments

Comments
 (0)