An open API service indexing awesome lists of open source software.

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.

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)