Spring Batch On Lambda with Sample Usage of SAM and Local Docker Run
#Lambda Local Testing Using Docker
mvn clean package -DskipTests docker build -t batch-lambda-demo . docker run -d -p 9000:8080 batch-lambda-demo
curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{"key1":"value1","key2":"value2"}'
#Lambda Local Testing using SAM
sam local invoke BatchLambdaDemo -e event.json
sam local start-api
curl -X POST http://localhost:3000/batch -d '{"key1":"value1"}'
Problem Recap Initial Issue: Spring Boot + AWS Lambda project couldn't run locally with SAM due to multiple build and packaging problems:
- Maven Shade Plugin Configuration Error:
- Error: Cannot find 'resource' in class ManifestResourceTransformer
- Cause: Incorrect transformer configuration syntax
- JAR Structure Incompatibility:
- Error: ClassNotFoundException: com.example.batch_lambda_demo.BatchLambdaHandler
- Cause: Spring Boot creates fat JARs with classes in BOOT-INF/classes/, but Lambda expects classes at root level
- Missing Database Dependency:
- Error: Failed to determine a suitable driver class
- Cause: Spring Batch requires a database but none was configured Resolution Steps
- Fixed Maven Build Configuration Before (broken):
xml After (working): org.apache.maven.plugins maven-shade-plugin 3.4.1 false
xml 2. Added Missing Database Dependency com.h2database h2 runtime
xml 3. Proper JAR Structure
- Before: Classes in BOOT-INF/classes/com/example/...
- After: Classes at root level com/example/...
- Solution: Maven Shade plugin creates Lambda-compatible flat JAR structure Final Working Commands
mvn clean package -DskipTests
sam local invoke BatchLambdaDemo -e event.json
bash Key Insight: Spring Boot's default packaging isn't Lambda-compatible. Maven Shade plugin creates the correct flat JAR structure that AWS Lambda runtime can load.