Demo project to showcase how to build an AWS Lambda using:
- Kotlin
- Gradle
- GraalVM
- Spring Boot 3
- Spring Reactive Web (WebFlux, Netty framework)
- Spring Cloud Function
- OpenMeteo API
- OpenAI API
- Docker & Testcontainers
Articles that were written based in this project:
The application requires JDK 17 at least on a GraalVM distribution.
$ sdk install java 22.3.r17-grl
$ sdk use java 22.3.r17-grl
./gradlew build
./gradlew bootRun
./gradlew nativeRun
Linux:
sam build
macOS:
AWS Lambda requires native applications to be built in an Amazon Linux compatible OS, so on macOS we need to run the build in a compatible Docker container.
-
Build the Docker image compatible with AWS Linux:
./aws-image/build-aws-image.sh
-
Run
sam build
specifying the Docker image:sam build --use-container --build-image tech.aaregall.lab/amazonlinux-graalvm:latest
Define the following environment variables on the deployment host.
export AWS_REGION=...
export OPENAI_API_KEY=...
sam deploy --region $AWS_REGION --parameter-overrides ParameterKey=OpenAiApiKey,ParameterValue=$OPENAI_API_KEY
sam logs -n SpringCloudFunctionLambda --stack-name aws-lambda-spring-cloud-function
sam delete SpringCloudFunctionLambda