https://github.com/arnauaregall/aws-lambda-spring-cloud-function
Exploring Spring Cloud Function, AI and AWS Lambda: building a native serverless application with Kotlin powered by OpenAI.
https://github.com/arnauaregall/aws-lambda-spring-cloud-function
aws docker graalvm kotlin lambda spring-boot spring-cloud-function testcontainers
Last synced: about 1 month ago
JSON representation
Exploring Spring Cloud Function, AI and AWS Lambda: building a native serverless application with Kotlin powered by OpenAI.
- Host: GitHub
- URL: https://github.com/arnauaregall/aws-lambda-spring-cloud-function
- Owner: ArnauAregall
- License: apache-2.0
- Created: 2023-06-03T11:35:46.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2023-07-09T12:07:54.000Z (almost 3 years ago)
- Last Synced: 2025-09-12T05:21:57.587Z (9 months ago)
- Topics: aws, docker, graalvm, kotlin, lambda, spring-boot, spring-cloud-function, testcontainers
- Language: Kotlin
- Homepage: https://aregall.tech/aws-lambda-spring-cloud-function-kotlin-graalvm-native-openai
- Size: 71.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# aws-lambda-spring-cloud-function
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:
- [Exploring Spring Cloud Function, AI and AWS Lambda: building a native serverless application with Kotlin powered by OpenAI.](https://aregall.tech/aws-lambda-spring-cloud-function-kotlin-graalvm-native-openai)
----
## Requirements
The application requires JDK 17 at least on a GraalVM distribution.
````shell
$ sdk install java 22.3.r17-grl
$ sdk use java 22.3.r17-grl
````
----
## Build and test
````
./gradlew build
````
----
## Running the application
### On a JDK
````
./gradlew bootRun
````
### Natively
````
./gradlew nativeRun
````
## Building the native AWS Lambda artifact with SAM
**Linux**:
````bash
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.
1. Build the Docker image compatible with AWS Linux:
````bash
./aws-image/build-aws-image.sh
````
2. Run `sam build` specifying the Docker image:
````bash
sam build --use-container --build-image tech.aaregall.lab/amazonlinux-graalvm:latest
````
## Deploy the application as an AWS Lambda using SAM
Define the following environment variables on the deployment host.
````bash
export AWS_REGION=...
export OPENAI_API_KEY=...
````
### Deploy the Lambda application
````bash
sam deploy --region $AWS_REGION --parameter-overrides ParameterKey=OpenAiApiKey,ParameterValue=$OPENAI_API_KEY
````
### See CloudWatch logs
````bash
sam logs -n SpringCloudFunctionLambda --stack-name aws-lambda-spring-cloud-function
````
### Delete the Lambda application
````bash
sam delete SpringCloudFunctionLambda
````