https://github.com/nireekshshetty/serverless-spring-api
A client (like Postman, browser, or frontend app) sends HTTP requests to API Gateway, which routes them to an AWS Lambda function that runs a Spring Boot app using Spring Cloud Function. This Lambda function processes the request and returns the appropriate response via API Gateway.
https://github.com/nireekshshetty/serverless-spring-api
api-gateway aws lambda serverless springboot
Last synced: 2 months ago
JSON representation
A client (like Postman, browser, or frontend app) sends HTTP requests to API Gateway, which routes them to an AWS Lambda function that runs a Spring Boot app using Spring Cloud Function. This Lambda function processes the request and returns the appropriate response via API Gateway.
- Host: GitHub
- URL: https://github.com/nireekshshetty/serverless-spring-api
- Owner: nireekshshetty
- License: mit
- Created: 2025-07-24T17:20:27.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-24T17:47:08.000Z (11 months ago)
- Last Synced: 2025-07-24T22:52:04.361Z (11 months ago)
- Topics: api-gateway, aws, lambda, serverless, springboot
- Language: Java
- Homepage:
- Size: 22.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ Serverless Spring Boot REST API (Java 21 + AWS Lambda + API Gateway)
A serverless REST API built using **Spring Boot 3** and deployed as an **AWS Lambda function** behind an **API Gateway**. This project demonstrates how to run a modern Spring Boot app in a fully serverless architecture without managing any servers.
---
## ๐ Project Overview
This project adapts a Spring Boot 3 application using **Spring Cloud Function** so it can run inside AWS Lambda. The API is exposed to the internet via **API Gateway**, making it suitable for stateless, cost-efficient backend services.
---
## โ๏ธ Tech Stack
- Java 21
- Spring Boot 3
- Spring Cloud Function
- AWS Lambda
- API Gateway
- Maven
- (Optional) AWS SAM for deployment
---
## ๐ง How the Project Works
> A **client** (like a browser, Postman, or frontend app) sends HTTP requests to **API Gateway**, which forwards the request to an **AWS Lambda function** running the **Spring Boot** application. The function handles the request and sends back a response via API Gateway.
### ๐ Request Flow:
```
Client โ API Gateway โ AWS Lambda (Spring Boot) โ Response
````
---
## ๐ฆ API Endpoints (Example)
| Method | Endpoint | Description |
|--------|------------------|---------------------------|
| GET | `/courses` | Fetch list of courses |
| POST | `/courses` | Add a new course |
| PUT | `/courses/{id}` | Update a course by ID |
| DELETE | `/courses/{id}` | Delete a course by ID |
---
## ๐ Project Structure
```bash
serverless-spring-api/
โโโ src/
โ โโโ main/java/
โ โโโ com/example/serverless/
โ โโโ handler/ # Lambda function handlers
โ โโโ model/ # Data models (DTOs)
โ โโโ service/ # Business logic (optional)
โ โโโ config/ # AWS-related config
โ โโโ ServerlessApplication.java # Spring Boot main class
โ
โโโ pom.xml # Maven dependencies and build setup
โโโ template.yaml # AWS SAM template (if using SAM)
โโโ README.md # Project documentation
````
---
## ๐งช Run Locally
You can test the Spring Boot app locally (optional):
```bash
mvn spring-boot:run
```
---
## ๐ Deployment Options
### Option 1: Manual Upload via AWS Console
1. Package the project:
```bash
mvn clean package
```
2. Go to AWS Lambda console, create a new function (Java 21), and upload the JAR.
3. Set the handler as:
```
org.springframework.cloud.function.adapter.aws.FunctionInvoker::handleRequest
```
### Option 2: Deploy Using AWS SAM (Recommended)
1. Install AWS CLI & AWS SAM CLI
2. Build & deploy:
```bash
sam build
sam deploy --guided
```
---
## ๐ Logs & Monitoring
Use AWS CloudWatch to view logs:
```bash
aws logs tail /aws/lambda/ --follow
```
---
## ๐จโ๐ป Author
**Nireeksh**
Java Backend Developer | Cloud & DevOps Enthusiast
[GitHub](https://github.com/nireekshshetty)