You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- This has been [fixed](https://github.com/apache/logging-log4j2/discussions/2364#discussioncomment-8950077) in Log4j 2.24.x. PT has been updated to use this version of Log4j
58
58
59
+
3.**Test Class Organization**
60
+
-**Issue**: Anonymous inner classes and lambda expressions in Mockito matchers cause `NoSuchMethodError` in GraalVM native tests
61
+
-**Solution**:
62
+
- Extract static inner test classes to separate concrete classes in the same package as the class under test
63
+
- Replace lambda expressions in `ArgumentMatcher` with concrete implementations
64
+
- Use `mockito-subclass` dependency in GraalVM profiles
Copy file name to clipboardExpand all lines: docs/utilities/validation.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,3 +292,53 @@ If you need to configure the Jackson ObjectMapper, you can use the `ValidationCo
292
292
}
293
293
}
294
294
```
295
+
296
+
## Advanced
297
+
298
+
### Lambda SnapStart priming
299
+
300
+
The Validation utility integrates with AWS Lambda SnapStart to improve restore durations. To make sure the SnapStart priming logic of this utility runs correctly, you need an explicit reference to `ValidationConfig` in your code to allow the library to register before SnapStart takes a memory snapshot. Learn more about what priming is in this [blog post](https://aws.amazon.com/blogs/compute/optimizing-cold-start-performance-of-aws-lambda-using-advanced-priming-strategies-with-snapstart/){target="_blank"}.
301
+
302
+
If you don't set a custom `ValidationConfig` in your code yet, make sure to reference `ValidationConfig` in your Lambda handler initialization code. This can be done by adding one of the following lines to your handler class:
Copy file name to clipboardExpand all lines: examples/README.md
+17-13Lines changed: 17 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,35 @@
1
1
# Powertools for AWS Lambda (Java) Examples
2
2
3
3
This directory holds example projects demoing different components of the Powertools for AWS Lambda (Java).
4
+
4
5
Each example can be copied from its subdirectory and used independently of the rest of this repository.
5
6
6
7
## Examples
7
8
8
9
*[powertools-examples-core-utilities](powertools-examples-core-utilities) - Demonstrates the core logging, tracing, and metrics modules with different build tools and languages
*[powertools-examples-serialization](powertools-examples-serialization) - Uses the serialization module to serialize and deserialize API Gateway & SQS payloads
*[powertools-examples-validation](powertools-examples-validation) - Uses the validation module to validate user requests received via API Gateway
18
27
*[powertools-examples-cloudformation](powertools-examples-cloudformation) - Deploys a Cloudformation custom resource
19
28
*[powertools-examples-batch](powertools-examples-batch) - Examples for each of the different batch processing deployments
29
+
*[powertools-examples-kafka](powertools-examples-kafka) - Examples for Kafka event processing
20
30
21
31
## Working with AWS Serverless Application Model (SAM) Examples
22
-
Many of the examples use [AWS Serverless Application Model](https://aws.amazon.com/serverless/sam/) (SAM). To get started
23
-
with them, you can use the SAM Command Line Interface (SAM CLI) to build it and deploy an example to AWS.
32
+
Many of the examples use [AWS Serverless Application Model](https://aws.amazon.com/serverless/sam/) (SAM). To get started with them, you can use the SAM Command Line Interface (SAM CLI) to build it and deploy an example to AWS.
24
33
25
34
To use the SAM CLI, you need the following tools.
26
35
@@ -29,17 +38,13 @@ To use the SAM CLI, you need the following tools.
* Docker - [Install Docker community edition](https://hub.docker.com/search/?type=edition&offering=community)
31
40
32
-
To learn more about SAM,
33
-
[check out the developer guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli.html).
34
-
You can use the CLI to [test events locally](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-local-invoke.html),
35
-
and [run the application locally](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-local-start-api.html),
36
-
amongst other things.
41
+
To learn more about SAM, [check out the developer guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli.html). You can use the CLI to [test events locally](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-local-invoke.html), and [run the application locally](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-local-start-api.html), amongst other things.
37
42
38
43
To build and deploy an example application for the first time, run the following in your shell:
39
44
40
45
```bash
41
46
# Switch to the directory containing an example for the powertools-idempotency module
42
-
$ cd powertools-examples-idempotency
47
+
$ cd powertools-examples-idempotency/sam
43
48
44
49
# Build and deploy the example
45
50
$ sam build
@@ -56,7 +61,7 @@ The first command will build the source of your application. The second command
56
61
57
62
You can find your API Gateway Endpoint URL in the output values displayed after deployment.
58
63
59
-
If you're not using SAM, you can look for examples for other tools under [powertools-examples-core](./powertools-examples-core)
64
+
If you're not using SAM, you can look for examples for other tools under [powertools-examples-core-utilities](./powertools-examples-core-utilities)
60
65
61
66
### External examples
62
67
@@ -69,10 +74,9 @@ You can find more examples in the https://github.com/aws/aws-sam-cli-app-templat
69
74
70
75
### SAM - Other Tools
71
76
72
-
If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit.
73
-
The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started.
77
+
If you prefer to use an integrated development environment (IDE) to build and test your application, you can use the AWS Toolkit. The AWS Toolkit is an open source plug-in for popular IDEs that uses the SAM CLI to build and deploy serverless applications on AWS. The AWS Toolkit also adds a simplified step-through debugging experience for Lambda function code. See the following links to get started.
# Powertools for AWS Lambda (Java) - CloudFormation Custom Resource Example with SAM on GraalVM
2
+
3
+
This project contains an example of a Lambda function using the CloudFormation module of Powertools for AWS Lambda (Java). For more information on this module, please refer to the [documentation](https://docs.powertools.aws.dev/lambda-java/utilities/custom_resources/).
4
+
5
+
In this example you pass in a bucket name as a parameter and upon CloudFormation events a call is made to a lambda. That lambda attempts to create the bucket on CREATE events, create a new bucket if the name changes with an UPDATE event and delete the bucket upon DELETE events.
6
+
7
+
Have a look at [App.java](../../src/main/java/helloworld/App.java) for the full details.
8
+
9
+
## Build the sample application
10
+
11
+
> [!NOTE]
12
+
> Building AWS Lambda packages on macOS (ARM64/Intel) for deployment on AWS Lambda (Linux x86_64 or ARM64) will result in incompatible binary dependencies that cause import errors at runtime.
13
+
14
+
Choose the appropriate build method based on your operating system:
15
+
16
+
### Build locally using Docker
17
+
18
+
Recommended for macOS and Windows users: Cross-compile using Docker to match target platform of Lambda:
sam build --use-container --build-image powertools-examples-cloudformation-sam-graalvm
24
+
```
25
+
26
+
**Note**: The Docker run command mounts your local Maven cache (`~/.m2`) and builds the native binary with SNAPSHOT support, then SAM packages the pre-built binary.
27
+
28
+
### Build on native OS
29
+
30
+
For Linux users with GraalVM installed:
31
+
32
+
```shell
33
+
export JAVA_HOME=<path to GraalVM>
34
+
cd ../..
35
+
mvn clean -Pnative-image package -DskipTests
36
+
cd infra/sam-graalvm
37
+
sam build
38
+
```
39
+
40
+
## Deploy the sample application
41
+
42
+
```shell
43
+
sam deploy --guided --parameter-overrides BucketNameParam=my-unique-bucket-2.3.0718
44
+
```
45
+
46
+
This sample is based on Serverless Application Model (SAM). To deploy it, check out the instructions for getting started with SAM in [the examples directory](../../../README.md)
47
+
48
+
## Test the application
49
+
50
+
The CloudFormation custom resource will be triggered automatically during stack deployment. You can monitor the Lambda function execution in CloudWatch Logs to see the custom resource handling CREATE, UPDATE, and DELETE events for the S3 bucket.
51
+
52
+
Check out [App.java](../../src/main/java/helloworld/App.java) to see how it works!
0 commit comments