Skip to content

Commit 9b2b6e8

Browse files
committed
Cosmetic fixes/formatting. Re-order imports in changed test files, fix/improve typos/language in documentation.
1 parent a1651ae commit 9b2b6e8

File tree

9 files changed

+73
-52
lines changed

9 files changed

+73
-52
lines changed

docs/FAQs.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,16 @@ but due to the impact on the developer experience it was decided to stick with t
148148

149149
Powertools core utilities, i.e. [logging](./core/logging.md), [metrics](./core/metrics.md) and [tracing](./core/tracing.md), include the [GraalVM Reachability Metadata (GRM)](https://www.graalvm.org/latest/reference-manual/native-image/metadata/) in the `META-INF` directories of the respective JARs. You can find a working example of Serverless Application Model (SAM) based application in the [examples](../examples/powertools-examples-core-utilities/sam-graalvm/README.md) directory.
150150

151-
These are typical steps you need to follow in a maven based Java project
151+
Below, you find typical steps you need to follow in a Maven based Java project:
152152

153153
### Set the environment to use GraalVM
154154

155155
```shell
156156
export JAVA_HOME=<path to GraalVM>
157157
```
158158

159-
### Use log4j > 2.24.0
160-
Log4j version `2.24.0` adds [support for GraalVM](https://github.com/apache/logging-log4j2/issues/1539#issuecomment-2106766878). Depending on your project's dependency hierarchy, older version of log4j might be included in the final dependency graph. Make sure version `>2.24.0` of these dependencies are used by your maven project:
159+
### Use log4j `>2.24.0`
160+
Log4j version `2.24.0` adds [support for GraalVM](https://github.com/apache/logging-log4j2/issues/1539#issuecomment-2106766878). Depending on your project's dependency hierarchy, older version of log4j might be included in the final dependency graph. Make sure version `>2.24.0` of these dependencies are used by your Maven project:
161161

162162
```xml
163163
<dependencies>
@@ -187,7 +187,7 @@ Log4j version `2.24.0` adds [support for GraalVM](https://github.com/apache/logg
187187

188188
### Add the AWS Lambda Java Runtime Interface Client dependency
189189

190-
Runtime Interface Client allow your function to receive invocation events from Lambda, send the response back to Lambda, and report errors to the Lambda service. Add the below dependency to your maven project:
190+
The Runtime Interface Client allows your function to receive invocation events from Lambda, send the response back to Lambda, and report errors to the Lambda service. Add the below dependency to your Maven project:
191191

192192
```xml
193193
<dependency>
@@ -197,11 +197,11 @@ Runtime Interface Client allow your function to receive invocation events from L
197197
</dependency>
198198
```
199199

200-
Also include the AWS Lambda GRM files by copying the `com.amazonaws`[directory](../examples/powertools-examples-core-utilities/sam-graalvm/src/main/resources/META-INF/native-image/) in your project's `META-INF/native-image` directory
200+
Also include the AWS Lambda GRM files by copying the `com.amazonaws` [directory](../examples/powertools-examples-core-utilities/sam-graalvm/src/main/resources/META-INF/native-image/) in your project's `META-INF/native-image` directory
201201

202202
### Build the native image
203203

204-
1. Use the `native-maven-plugin` to build the native image. You can do this by adding the plugin to your `pom.xml` and creating a build profile called `native-image` that can build the native image of your Lambda function:
204+
Use the `native-maven-plugin` to build the native image. You can do this by adding the plugin to your `pom.xml` and creating a build profile called `native-image` that can build the native image of your Lambda function:
205205

206206
```xml
207207
<profiles>
@@ -239,16 +239,16 @@ Also include the AWS Lambda GRM files by copying the `com.amazonaws`[directory](
239239
</profiles>
240240
```
241241

242-
2. Create a docker image using a Dockerfile like [this](../examples/powertools-examples-core-utilities/sam-graalvm/Dockerfile) to create an x86 based build image.
242+
Create a Docker image using a `Dockerfile` like [this](../examples/powertools-examples-core-utilities/sam-graalvm/Dockerfile) to create an x86 based build image.
243243

244244
```shell
245245
docker build --platform linux/amd64 . -t your-org/your-app-graalvm-builder
246246
```
247247

248-
3. Create the native image of you Lambda function using the docker command below.
248+
Create the native image of you Lambda function using the Docker command below.
249249

250250
```shell
251251
docker run --platform linux/amd64 -it -v `pwd`:`pwd` -w `pwd` -v ~/.m2:/root/.m2 your-org/your-app-graalvm-builder mvn clean -Pnative-image package
252252

253253
```
254-
The native image is created in the target directory.
254+
The native image is created in the `target/` directory.

docs/core/logging.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ we provide [built-in JMESPath expressions](#built-in-correlation-id-expressions)
444444

445445
#### Custom keys
446446

447-
** Using StructuredArguments **
447+
**Using StructuredArguments**
448448

449449
To append additional keys in your logs, you can use the `StructuredArguments` class:
450450

@@ -624,7 +624,7 @@ To append additional keys in your logs, you can use the `StructuredArguments` cl
624624
}
625625
```
626626

627-
** Using MDC **
627+
**Using MDC**
628628

629629
Mapped Diagnostic Context (MDC) is essentially a Key-Value store. It is supported by the [SLF4J API](https://www.slf4j.org/manual.html#mdc){target="_blank"},
630630
[logback](https://logback.qos.ch/manual/mdc.html){target="_blank"} and log4j (known as [ThreadContext](https://logging.apache.org/log4j/2.x/manual/thread-context.html){target="_blank"}). You can use the following standard:
@@ -1048,4 +1048,4 @@ Use the `LambdaEcsEncoder` rather than the `LambdaJsonEncoder` when configuring
10481048
<appender-ref ref="console" />
10491049
</root>
10501050
</configuration>
1051-
```
1051+
```
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,64 @@
1-
# Powertools for AWS Lambda (Java) - Core Utilities Example with SAM on GraalVM
1+
# Powertools for AWS Lambda (Java) - Core Utilities Example with SAM on GraalVM
22

33
This project demonstrates the Lambda for Powertools Java module deployed using [Serverless Application Model](https://aws.amazon.com/serverless/sam/) running as a GraalVM native image.
44

55
For general information on the deployed example itself, you can refer to the parent [README](../README.md)
66

77
## Configuration
8-
- SAM uses [template.yaml](template.yaml) to define the application's AWS resources.
9-
This file defines the Lambda function to be deployed as well as API Gateway for it.
108

11-
- Set the environment to use GraalVM
9+
- SAM uses [template.yaml](template.yaml) to define the application's AWS resources.
10+
This file defines the Lambda function to be deployed as well as API Gateway for it.
1211

13-
```shell
12+
- Set the environment to use GraalVM
13+
14+
```shell
1415
export JAVA_HOME=<path to GraalVM>
1516
```
1617

1718
## Build the sample application
1819

1920
- Build the Docker image that will be used as the environment for SAM build:
21+
2022
```shell
2123
docker build --platform linux/amd64 . -t powertools-examples-core-sam-graalvm
2224
```
2325

2426
- Build the SAM project using the docker image
27+
2528
```shell
2629
sam build --use-container --build-image powertools-examples-core-sam-graalvm
27-
2830
```
31+
2932
#### [Optional] Building with -SNAPSHOT versions of PowerTools
33+
3034
- If you are testing the example with a -SNAPSHOT version of PowerTools, the maven build inside the docker image will fail. This is because the -SNAPSHOT version of the PowerTools library that you are working on is still not available in maven central/snapshot repository.
31-
To get around this, follow these steps:
32-
- Create the native image using the `docker` command below on your development machine. The native image is created in the `target` directory.
33-
- ```docker run --platform linux/amd64 -it -v `pwd`:`pwd` -w `pwd` -v ~/.m2:/root/.m2 powertools-examples-core-sam-graalvm mvn clean -Pnative-image package -DskipTests```
35+
To get around this, follow these steps:
36+
- Create the native image using the `docker` command below on your development machine. The native image is created in the `target` directory.
37+
- `` docker run --platform linux/amd64 -it -v `pwd`:`pwd` -w `pwd` -v ~/.m2:/root/.m2 powertools-examples-core-sam-graalvm mvn clean -Pnative-image package -DskipTests ``
3438
- Edit the [`Makefile`](Makefile) remove this line
35-
- ```mvn clean package -P native-image```
39+
- `mvn clean package -P native-image`
3640
- Build the SAM project using the docker image
37-
- ```sam build --use-container --build-image powertools-examples-core-sam-graalvm```
41+
- `sam build --use-container --build-image powertools-examples-core-sam-graalvm`
3842

3943
## Deploy the sample application
44+
4045
- SAM deploy
4146

42-
sam deploy
47+
```shell
48+
sam deploy
49+
```
4350

4451
To deploy the example, check out the instructions for getting
4552
started with SAM in [the examples directory](../../README.md)
4653

4754
## Additional notes
4855

4956
You can watch the trace information or log information using the SAM CLI:
57+
5058
```bash
5159
# Tail the logs
5260
sam logs --tail $MY_STACK
5361

5462
# Tail the traces
5563
sam traces --tail
56-
```
64+
```

powertools-common/src/test/java/software/amazon/lambda/powertools/common/internal/LambdaHandlerProcessorTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
import static org.mockito.Mockito.mock;
2020
import static org.mockito.Mockito.when;
2121

22-
import com.amazonaws.services.lambda.runtime.Context;
23-
import com.amazonaws.services.lambda.runtime.RequestHandler;
24-
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
2522
import java.io.InputStream;
2623
import java.io.OutputStream;
2724
import java.util.Optional;
25+
2826
import org.aspectj.lang.ProceedingJoinPoint;
2927
import org.aspectj.lang.Signature;
3028
import org.junit.jupiter.api.Test;
3129
import org.junitpioneer.jupiter.ClearEnvironmentVariable;
3230
import org.junitpioneer.jupiter.SetEnvironmentVariable;
3331

32+
import com.amazonaws.services.lambda.runtime.Context;
33+
import com.amazonaws.services.lambda.runtime.RequestHandler;
34+
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
35+
3436
class LambdaHandlerProcessorTest {
3537

3638
private Signature signature = mock(Signature.class);
@@ -234,4 +236,4 @@ private ProceedingJoinPoint mockRequestHandlerPjp(Class handlerClass, Object[] h
234236
when(pjpMock.getSignature()).thenReturn(signature);
235237
return pjpMock;
236238
}
237-
}
239+
}

powertools-logging/src/test/java/software/amazon/lambda/powertools/logging/internal/LambdaLoggingAspectTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@
2929
import static software.amazon.lambda.powertools.logging.internal.PowertoolsLoggedFields.FUNCTION_VERSION;
3030
import static software.amazon.lambda.powertools.logging.internal.PowertoolsLoggedFields.SERVICE;
3131

32-
import com.amazonaws.services.lambda.runtime.Context;
33-
import com.amazonaws.services.lambda.runtime.RequestHandler;
34-
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
35-
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
36-
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
37-
import com.amazonaws.services.lambda.runtime.events.ApplicationLoadBalancerRequestEvent;
38-
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
39-
import com.amazonaws.services.lambda.runtime.tests.annotations.Event;
40-
import com.fasterxml.jackson.databind.ObjectMapper;
4132
import java.io.ByteArrayInputStream;
4233
import java.io.ByteArrayOutputStream;
4334
import java.io.File;
@@ -55,6 +46,7 @@
5546
import java.util.Collections;
5647
import java.util.List;
5748
import java.util.Map;
49+
5850
import org.junit.jupiter.api.AfterEach;
5951
import org.junit.jupiter.api.BeforeEach;
6052
import org.junit.jupiter.api.Test;
@@ -68,6 +60,17 @@
6860
import org.slf4j.MDC;
6961
import org.slf4j.event.Level;
7062
import org.slf4j.test.TestLogger;
63+
64+
import com.amazonaws.services.lambda.runtime.Context;
65+
import com.amazonaws.services.lambda.runtime.RequestHandler;
66+
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
67+
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
68+
import com.amazonaws.services.lambda.runtime.events.APIGatewayV2HTTPEvent;
69+
import com.amazonaws.services.lambda.runtime.events.ApplicationLoadBalancerRequestEvent;
70+
import com.amazonaws.services.lambda.runtime.events.SQSEvent;
71+
import com.amazonaws.services.lambda.runtime.tests.annotations.Event;
72+
import com.fasterxml.jackson.databind.ObjectMapper;
73+
7174
import software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor;
7275
import software.amazon.lambda.powertools.logging.argument.KeyValueArgument;
7376
import software.amazon.lambda.powertools.logging.handlers.PowertoolsLogAlbCorrelationId;
@@ -780,4 +783,4 @@ private void resetLogLevel(Level level)
780783
setLogLevels.invoke(null, level);
781784
writeStaticField(LambdaLoggingAspect.class, "LEVEL_AT_INITIALISATION", level, true);
782785
}
783-
}
786+
}

powertools-metrics/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,4 +204,4 @@
204204
</plugin>
205205
</plugins>
206206
</build>
207-
</project>
207+
</project>

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/MetricsLoggerTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,21 @@
1717
import static java.util.Collections.emptyMap;
1818
import static org.assertj.core.api.Assertions.assertThat;
1919

20-
import com.fasterxml.jackson.core.JsonProcessingException;
21-
import com.fasterxml.jackson.databind.ObjectMapper;
2220
import java.io.ByteArrayOutputStream;
2321
import java.io.PrintStream;
2422
import java.util.ArrayList;
2523
import java.util.LinkedHashMap;
2624
import java.util.Map;
2725
import java.util.function.Consumer;
26+
2827
import org.junit.jupiter.api.AfterEach;
2928
import org.junit.jupiter.api.BeforeEach;
3029
import org.junit.jupiter.api.Test;
3130
import org.junitpioneer.jupiter.SetEnvironmentVariable;
31+
32+
import com.fasterxml.jackson.core.JsonProcessingException;
33+
import com.fasterxml.jackson.databind.ObjectMapper;
34+
3235
import software.amazon.cloudwatchlogs.emf.logger.MetricsLogger;
3336
import software.amazon.cloudwatchlogs.emf.model.DimensionSet;
3437
import software.amazon.cloudwatchlogs.emf.model.StorageResolution;
@@ -226,4 +229,4 @@ private Map<String, Object> readAsJson(String s) {
226229
}
227230
return emptyMap();
228231
}
229-
}
232+
}

powertools-metrics/src/test/java/software/amazon/lambda/powertools/metrics/internal/LambdaMetricsAspectTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,24 @@
2121
import static org.mockito.Mockito.when;
2222
import static org.mockito.MockitoAnnotations.openMocks;
2323

24-
import com.amazonaws.services.lambda.runtime.Context;
25-
import com.amazonaws.services.lambda.runtime.RequestHandler;
26-
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
27-
import com.fasterxml.jackson.core.JsonProcessingException;
28-
import com.fasterxml.jackson.databind.ObjectMapper;
2924
import java.io.ByteArrayInputStream;
3025
import java.io.ByteArrayOutputStream;
3126
import java.io.IOException;
3227
import java.io.PrintStream;
3328
import java.util.Map;
29+
3430
import org.junit.jupiter.api.AfterEach;
3531
import org.junit.jupiter.api.BeforeEach;
3632
import org.junit.jupiter.api.Test;
3733
import org.junitpioneer.jupiter.SetEnvironmentVariable;
3834
import org.mockito.Mock;
3935

36+
import com.amazonaws.services.lambda.runtime.Context;
37+
import com.amazonaws.services.lambda.runtime.RequestHandler;
38+
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
39+
import com.fasterxml.jackson.core.JsonProcessingException;
40+
import com.fasterxml.jackson.databind.ObjectMapper;
41+
4042
import software.amazon.cloudwatchlogs.emf.exception.DimensionSetExceededException;
4143
import software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor;
4244
import software.amazon.lambda.powertools.metrics.MetricsUtils;

powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/internal/LambdaTracingAspectTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,21 @@
2121
import static org.mockito.Mockito.when;
2222
import static org.mockito.MockitoAnnotations.openMocks;
2323

24-
import com.amazonaws.services.lambda.runtime.Context;
25-
import com.amazonaws.services.lambda.runtime.RequestHandler;
26-
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
27-
import com.amazonaws.xray.AWSXRay;
2824
import java.io.ByteArrayInputStream;
2925
import java.io.ByteArrayOutputStream;
3026
import java.io.IOException;
27+
3128
import org.junit.jupiter.api.AfterEach;
3229
import org.junit.jupiter.api.BeforeEach;
3330
import org.junit.jupiter.api.Test;
3431
import org.junitpioneer.jupiter.SetEnvironmentVariable;
3532
import org.mockito.Mock;
33+
34+
import com.amazonaws.services.lambda.runtime.Context;
35+
import com.amazonaws.services.lambda.runtime.RequestHandler;
36+
import com.amazonaws.services.lambda.runtime.RequestStreamHandler;
37+
import com.amazonaws.xray.AWSXRay;
38+
3639
import software.amazon.lambda.powertools.common.internal.LambdaHandlerProcessor;
3740
import software.amazon.lambda.powertools.tracing.handlers.PowerToolDisabled;
3841
import software.amazon.lambda.powertools.tracing.handlers.PowerToolDisabledForStream;

0 commit comments

Comments
 (0)