Source code for the ebook "Reactive Microservices with Spring Boot and AWS Lambda". A complete project with Spring Boot 4.1.0, Java 25, Project Reactor, and AWS Lambda. Production-ready with support for native compilation via GraalVM.
π Get the full ebook:
- π Amazon Kindle
- π Hotmart
- π³ Gumroad
- Java 25 + Spring Boot 4.1.0 + Spring WebFlux (Ebook: Section 0.13, 0.14)
- Spring Cloud Function 5.0.3 (Spring Cloud 2025.1.2) (Ebook: Section 3.2)
- Project Reactor (Mono/Flux) (Ebook: Section 2.3)
- Spring Cloud Function + AWS Lambda (Ebook: Section 3.3, 3.4)
- GraalVM Native Image (native compilation) (Ebook: Section 4.2, 4.4)
- AWS SAM + LocalStack (local development) (Ebook: Section 1.5, 3.6)
- GitHub Actions (CI/CD) (Ebook: Section 6.6)
- Micrometer + Spring Actuator (observability) (Ebook: Section 6.4)
API Gateway HTTP API β AWS Lambda β Spring Cloud Function β Project Reactor
β
CloudWatch Logs / DynamoDB / SQS
Requirements: Java 25, Gradle 9.6.1+ (bundled), Docker, AWS SAM CLI (Ebook: Section 1.2)
# Clone and build
git clone <repository-url>
cd reactive-microservices-aws-lambda-java25
# Use the Java 25 version (recommended)
git checkout v1.0.0-java25
# Or use the previous Java 21 version (reference only)
# git checkout v1.0.0-java21
./gradlew clean build # Ebook: Section 1.4, 1.8
# Run tests
./gradlew test # Ebook: Section 2.8
# Start the local application
./gradlew :lambda-core:bootRun # Ebook: Section 1.6# Start LocalStack
docker-compose up -d localstack # Ebook: Section 1.5, 5.10
# Test with SAM
cd lambda-infra
sam build --template template.yaml # Ebook: Section 3.6
sam local invoke "ReactiveFunction" --event events/hello.json # Ebook: Section 3.6
sam local start-api # Ebook: Section 3.6# Build the multi-stage image (Java 25 + Spring Boot)
docker build -t reactive-lambda .
# Run the function as a WebFlux service on localhost (uses 8081 if 8080 is taken)
docker run --rm -d -p 8081:8080 --name reactive-lambda reactive-lambda
# Smoke test against the endpoint and actuators exposed on the container
curl -i "http://localhost:8081/hello?name=Marcos"
curl -i "http://localhost:8081/actuator/health"Example response:
HTTP/1.1 200 OK
Content-Type: application/json
{"message":"ok","name":"Marcos","greeting":"Hello, Marcos!","timestamp":"2025-12-07T22:25:41.234Z"}
# Bash / zsh
docker run --rm -it \
-v ${PWD}:/workspace \
-w /workspace \
public.ecr.aws/sam/build-java25:latest \
bash -lc "./gradlew test"
docker run --rm -it \
-v ${PWD}:/workspace \
-w /workspace \
public.ecr.aws/sam/build-java25:latest \
bash -lc "sam build --template lambda-infra/template.yaml && sam validate"# PowerShell
docker run --rm -it `
-v ${PWD}:/workspace `
-w /workspace `
public.ecr.aws/sam/build-java25:latest `
bash -lc "./gradlew test"
docker run --rm -it `
-v ${PWD}:/workspace `
-w /workspace `
public.ecr.aws/sam/build-java25:latest `
bash -lc "sam build --template lambda-infra/template.yaml && sam validate"cd lambda-infra
sam deploy --guided # Ebook: Section 3.7, 3.11.1π See in the ebook:
- Section 3.7 (Deploying to AWS)
- Section 3.11.1 (Deploying with API Gateway)
- Section 4.8 (Deploying the native binary to AWS Lambda)
./gradlew test # All tests
./gradlew :lambda-core:test # lambda-core only
./gradlew :lambda-tests:test # Integration onlyexport JAVA_HOME=/path/to/graalvm-jdk-25 # Ebook: Section 4.5.1
./gradlew :lambda-core:nativeCompile # Ebook: Section 4.4, 4.8π See in the ebook: Section 4 (Startup and performance optimization with GraalVM Native) for full details on configuration, optimizations, and deploying the native binary.
# Health check
curl http://localhost:8080/actuator/health # Ebook: Section 6.4
# Metrics
curl http://localhost:8080/actuator/metrics # Ebook: Section 6.4π See in the ebook:
- Section 6.3 (Structured logging)
- Section 6.4 (Custom metrics with Micrometer)
- Section 6.5 (Distributed tracing with AWS X-Ray)
Error: "Cannot find handler"
./gradlew clean buildLocalStack not responding
docker-compose restart localstack
curl http://localhost:4566/_localstack/healthGraalVM Native Build fails
export GRADLE_OPTS="-Xmx4g"
./gradlew clean :lambda-core:nativeCompileβββ lambda-core/ # Main Lambda code (Ebook: Section 1.7, 3.9)
β βββ src/main/java/com/example/lambda/
β β βββ FunctionConfig.java # Ebook: Section 3.9.1
β β βββ HelloHandler.java # Ebook: Section 3.9.2
β β βββ HelloController.java # Ebook: Section 2.4, 2.5
β β βββ GlobalExceptionHandler.java # Ebook: Section 3.10, 2.7
β β βββ RequestValidator.java # Ebook: Section 3.10.1
β βββ src/main/resources/
β βββ application.yml # Ebook: Section 1.9.1
β βββ application-dev.yml # Ebook: Section 1.9.2
β βββ application-prod.yml # Ebook: Section 1.9.3
βββ lambda-infra/ # SAM template (Ebook: Section 3.11)
β βββ template.yaml # Ebook: Section 3.11
β βββ events/ # Ebook: Section 3.6
βββ lambda-tests/ # Integration tests (Ebook: Section 2.8)
βββ buildSrc/ # Gradle conventions (Ebook: Section 1.4)
βββ src/main/kotlin/conventions.gradle.kts # Ebook: Section 0.14, 1.4
π Cross-Reference Document: See
REFERENCIAS_CRUZADAS_EBOOK_PROYECTO.mdfor a full mapping between the ebook and the project files.
The project includes Git tags to make it easy to access different versions:
-
v1.0.0-java25(current): Full version migrated to Java 25- Java 25 LTS, Spring Boot 3.4.13, Gradle 9.2.1
- AWS Lambda runtime:
java25 - Recommended for following the updated ebook
-
v1.0.0-java21: Last version before the Java 25 migration- Java 21, Spring Boot 3.3.1
- Useful for comparing changes or seeing the prior state
# List all available versions
git tag -l
# Switch to the Java 25 version (recommended)
git checkout v1.0.0-java25
# Switch to the Java 21 version (reference only)
git checkout v1.0.0-java21
# See differences between versions
git diff v1.0.0-java21 v1.0.0-java25
# Go back to the latest version
git checkout main- π Amazon Kindle
- π Hotmart
- π³ Gumroad
π Cross-References: This project is 100% aligned with the ebook. See
REFERENCIAS_CRUZADAS_EBOOK_PROYECTO.mdto navigate between the ebook and the source code.
- Spring Boot (Ebook: Section 0.13, 1.4)
- Spring Cloud Function (Ebook: Section 3.2)
- AWS SAM (Ebook: Section 3.6, 3.11)
- Project Reactor (Ebook: Section 2.3)
If this project has been useful to you:
- π Get the full ebook - Amazon | Hotmart | Gumroad
- β Buy Me a Coffee
- π³ PayPal Donate
- β Star the repository
Thanks for your support! π
- Fork the project
- Create a branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Copyright (c) 2025 Marcos Raimundo Lozina. All rights reserved.
This project is protected by copyright. See the LICENSE file for full details.
Usage: Personal and educational use only. Any commercial use requires prior authorization.
Marcos Raimundo Lozina
Created as a reference project for serverless reactive microservices with Spring Boot and AWS Lambda.