In this sample, you'll build a native GraalVM image for running Spring Boot 4.0 and Spring Framework 7.0 web workloads in AWS Lambda.
Important: Spring Boot 4.0 requires GraalVM 25 for native image compilation. GraalVM 21 is not compatible.
You first need to build the function, then you will deploy it to AWS Lambda.
Please note that the sample is for x86 architectures. In case you want to build and run it on ARM, e.g. Apple Mac M1, M2, ...
you must change the according line in the Dockerfile to ENV ARCHITECTURE aarch64.
In addition, uncomment the arm64 Architectures section in template.yml.
Before starting the build, you must clone or download the code in pet-store-native.
- Change into the project directory:
samples/springboot4/pet-store-native - Run the following to build a Docker container image with GraalVM 25 which will include all the necessary dependencies to build the application
docker build -t al2023-graalvm25:native-web . - Build the application within the previously created build image
docker run -it -v `pwd`:`pwd` -w `pwd` -v ~/.m2:/root/.m2 al2023-graalvm25:native-web mvn clean native:compile -Pnative - After the build finishes, you need to deploy the function:
sam deploy --guided
This will deploy your application and will attach an AWS API Gateway Once the deployment is finished you should see the following:
Key ServerlessWebNativeApi
Description URL for application
Value https://xxxxxxxx.execute-api.us-east-2.amazonaws.com/pets
You can now simply execute GET on this URL and see the listing fo all pets.