generated from amazon-archives/__template_MIT-0
-
Notifications
You must be signed in to change notification settings - Fork 96
feat(graalvm): GraalVM support for powertools-cloudformation #2090
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e08ac64
Add GraalVM profile to powertools-cloudformation. Make unit tests com…
phipag 0c31061
Restore CloudFormationResponse.java from incorrect formatting changes.
phipag e2caae0
Add missing @Override.
phipag 39782fc
Fix Sonar finding.
phipag 0ac151c
Make CloudFormationResponse public as it is needed for subclass mockm…
phipag 2dbaab7
Add reflective metadata for powertools-cloudformation. Add sam-graalv…
phipag c276e6f
Test conditional graalvm builds based on PR changes.
phipag fc0af96
Use correct changed-files GH action.
phipag f53801f
Attempt to fix bug in detecting module changes.
phipag f62a46e
Use space separator to detect changed files.
phipag 3a69e9e
New attempt to try to fix module detection.
phipag de951de
Attempt to fix bug in detecting module changes.
phipag 9443963
Add debug output to understand why changed module detection not working.
phipag 1f2c8dd
Add more debug statemetns.
phipag 29e6063
Fix issue with pom.xml root path detection.
phipag 4304ae2
Remove debug logs again.
phipag 505bb11
Merge branch 'main' into phipag/issue1838
phipag 3283066
Merge branch 'main' into phipag/issue1838
phipag cd70d38
Use github ::group::.
phipag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
build-HelloWorldFunction: | ||
chmod +x target/hello-world | ||
cp target/hello-world $(ARTIFACTS_DIR) # (ARTIFACTS_DIR --> https://github.com/aws/aws-lambda-builders/blob/develop/aws_lambda_builders/workflows/custom_make/DESIGN.md#implementation) | ||
chmod +x src/main/config/bootstrap | ||
cp src/main/config/bootstrap $(ARTIFACTS_DIR) |
14 changes: 14 additions & 0 deletions
14
examples/powertools-examples-cloudformation/infra/sam-graalvm/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Use the official AWS SAM base image for Java 21 | ||
FROM public.ecr.aws/sam/build-java21@sha256:a5554d68374e19450c6c88448516ac95a9acedc779f318040f5c230134b4e461 | ||
|
||
# Install GraalVM dependencies | ||
RUN curl -4 -L curl https://download.oracle.com/graalvm/21/latest/graalvm-jdk-21_linux-x64_bin.tar.gz | tar -xvz | ||
RUN mv graalvm-jdk-21.* /usr/lib/graalvm | ||
|
||
# Make native image and mvn available on CLI | ||
RUN ln -s /usr/lib/graalvm/bin/native-image /usr/bin/native-image | ||
RUN ln -s /usr/lib/maven/bin/mvn /usr/bin/mvn | ||
|
||
# Set GraalVM as default | ||
ENV JAVA_HOME=/usr/lib/graalvm | ||
ENV PATH=/usr/lib/graalvm/bin:$PATH |
52 changes: 52 additions & 0 deletions
52
examples/powertools-examples-cloudformation/infra/sam-graalvm/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Powertools for AWS Lambda (Java) - CloudFormation Custom Resource Example with SAM on GraalVM | ||
|
||
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/). | ||
|
||
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. | ||
|
||
Have a look at [App.java](../../src/main/java/helloworld/App.java) for the full details. | ||
|
||
## Build the sample application | ||
|
||
> [!NOTE] | ||
> 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. | ||
|
||
Choose the appropriate build method based on your operating system: | ||
|
||
### Build locally using Docker | ||
|
||
Recommended for macOS and Windows users: Cross-compile using Docker to match target platform of Lambda: | ||
|
||
```shell | ||
docker build --platform linux/amd64 . -t powertools-examples-cloudformation-sam-graalvm | ||
docker run --platform linux/amd64 -it -v `pwd`/../..:`pwd`/../.. -w `pwd`/../.. -v ~/.m2:/root/.m2 powertools-examples-cloudformation-sam-graalvm mvn clean -Pnative-image package -DskipTests | ||
sam build --use-container --build-image powertools-examples-cloudformation-sam-graalvm | ||
``` | ||
|
||
**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. | ||
|
||
### Build on native OS | ||
|
||
For Linux users with GraalVM installed: | ||
|
||
```shell | ||
export JAVA_HOME=<path to GraalVM> | ||
cd ../.. | ||
mvn clean -Pnative-image package -DskipTests | ||
cd infra/sam-graalvm | ||
sam build | ||
``` | ||
|
||
## Deploy the sample application | ||
|
||
```shell | ||
sam deploy --guided --parameter-overrides BucketNameParam=my-unique-bucket-2.3.0718 | ||
``` | ||
|
||
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) | ||
|
||
## Test the application | ||
|
||
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. | ||
|
||
Check out [App.java](../../src/main/java/helloworld/App.java) to see how it works! |
49 changes: 49 additions & 0 deletions
49
examples/powertools-examples-cloudformation/infra/sam-graalvm/template.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
AWSTemplateFormatVersion: '2010-09-09' | ||
Transform: AWS::Serverless-2016-10-31 | ||
Description: > | ||
powertools-examples-cloudformation-graalvm | ||
|
||
Sample SAM Template for powertools-examples-cloudformation with GraalVM native image | ||
|
||
Globals: | ||
Function: | ||
Timeout: 20 | ||
|
||
Parameters: | ||
BucketNameParam: | ||
Type: String | ||
|
||
Resources: | ||
HelloWorldCustomResource: | ||
Type: AWS::CloudFormation::CustomResource | ||
Properties: | ||
ServiceToken: !GetAtt HelloWorldFunction.Arn | ||
BucketName: !Ref BucketNameParam | ||
|
||
HelloWorldFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
CodeUri: ../../ | ||
Handler: helloworld.App::handleRequest | ||
Runtime: provided.al2023 | ||
Architectures: | ||
- x86_64 | ||
MemorySize: 512 | ||
Policies: | ||
- Statement: | ||
- Sid: bucketaccess1 | ||
Effect: Allow | ||
Action: | ||
- s3:GetLifecycleConfiguration | ||
- s3:PutLifecycleConfiguration | ||
- s3:CreateBucket | ||
- s3:ListBucket | ||
- s3:DeleteBucket | ||
Resource: '*' | ||
Metadata: | ||
BuildMethod: makefile | ||
|
||
Outputs: | ||
HelloWorldFunction: | ||
Description: "Hello World Lambda Function ARN" | ||
Value: !GetAtt HelloWorldFunction.Arn |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.