|
| 1 | +# AWS Spring Boot Serverless Template |
| 2 | + |
| 3 | +A boilerplate project to kickstart your **Spring Boot** applications with **AWS Serverless** architecture. This template is tailored for developers looking to rapidly build, test, and deploy Spring Boot applications using **AWS Lambda**, **API Gateway**, and **CloudFormation** — all with minimal setup. |
| 4 | + |
| 5 | +## 🚀 About This Project |
| 6 | + |
| 7 | +This project provides a fully functional template to deploy Spring Boot applications on AWS Lambda using API Gateway as the HTTP interface. It is ideal for developers and DevOps engineers who want a scalable, cost-effective, and event-driven backend using Java and Spring Boot without managing traditional servers. |
| 8 | + |
| 9 | +Use this template to: |
| 10 | + |
| 11 | +* Build stateless Spring Boot APIs |
| 12 | +* Automatically provision infrastructure using AWS SAM and CloudFormation |
| 13 | +* Handle deployments via a streamlined `deploy.sh` script |
| 14 | + |
| 15 | +## 📚 Documentation |
| 16 | + |
| 17 | +This template integrates the following AWS services: |
| 18 | + |
| 19 | +* **AWS Lambda** – Serverless compute for running backend logic |
| 20 | +* **API Gateway** – Expose RESTful APIs to users |
| 21 | +* **S3** – Store build artifacts and configurations |
| 22 | +* **CloudFormation** – Define and manage infrastructure as code |
| 23 | + |
| 24 | +## 🔌 API Reference |
| 25 | + |
| 26 | +### `GET /health` |
| 27 | + |
| 28 | +Performs a health check on the deployed Spring Boot application. |
| 29 | + |
| 30 | +**Request:** |
| 31 | + |
| 32 | +```http |
| 33 | +GET /health |
| 34 | +``` |
| 35 | + |
| 36 | +**Response:** |
| 37 | + |
| 38 | +```json |
| 39 | +{ |
| 40 | + "message": "Health check successful", |
| 41 | + "status": 0, |
| 42 | + "success": true, |
| 43 | + "data": { |
| 44 | + "status": "UP", |
| 45 | + "message": "Application health check completed successfully", |
| 46 | + "timestamp": "2025-06-16T10:26:21.908590756", |
| 47 | + "details": { |
| 48 | + "memory": "available", |
| 49 | + "diskSpace": "available", |
| 50 | + "uptime": 4550 |
| 51 | + }, |
| 52 | + "uptime": 4551, |
| 53 | + "version": "1.0.0" |
| 54 | + } |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +Here's the updated `🧪 Demo & Deployment` section, professionally formatted and integrated with the new options and CloudWatch monitoring notes: |
| 59 | + |
| 60 | +## 🧪 Demo & Deployment |
| 61 | + |
| 62 | +You can build, test, and deploy your Spring Boot application using the included `deploy.sh` script, which simplifies the entire lifecycle of your serverless app. |
| 63 | + |
| 64 | +### ✅ Usage |
| 65 | + |
| 66 | +```bash |
| 67 | +./deploy.sh [OPTIONS] |
| 68 | +``` |
| 69 | + |
| 70 | +### 🔧 Available Options |
| 71 | + |
| 72 | +| Option | Description | |
| 73 | +| --------------------- | ------------------------------------------ | |
| 74 | +| `-h`, `--help` | Show help message | |
| 75 | +| `-t`, `--test-only` | Test the existing deployment | |
| 76 | +| `-b`, `--build-only` | Only build the project (no deployment) | |
| 77 | +| `-d`, `--deploy-only` | Only deploy (skip build and test) | |
| 78 | +| `--clean` | Clean deployment (delete and redeploy all) | |
| 79 | +| `--logs` | Show recent CloudWatch logs | |
| 80 | +| `--tail-logs` | Tail CloudWatch logs in real-time | |
| 81 | + |
| 82 | +### ⚙️ Configuration |
| 83 | + |
| 84 | +On the first run, the script will interactively prompt for: |
| 85 | + |
| 86 | +* **Stack Name** (default: `spring-boot-demo`) |
| 87 | +* **S3 Bucket Name** (default: `spring-boot-demo-artifacts-ACCOUNT_ID`) |
| 88 | +* **AWS Region** (default: `us-east-1`) |
| 89 | + |
| 90 | +These values are saved in `samconfig.toml` for future runs. |
| 91 | +Use `--clean` to delete all deployed resources and reset the configuration. |
| 92 | + |
| 93 | +### 🌍 Environment Variables |
| 94 | + |
| 95 | +You can override default behavior using environment variables: |
| 96 | + |
| 97 | +| Variable | Description | Default | |
| 98 | +| -------------- | -------------------------------------- | ------------------ | |
| 99 | +| `PROJECT_NAME` | The name of the project | `spring-boot-demo` | |
| 100 | +| `REGION` | AWS Region to deploy to | `us-east-1` | |
| 101 | +| `STAGE` | Deployment stage (e.g., `dev`, `prod`) | `dev` | |
| 102 | + |
| 103 | +### 📊 CloudWatch Monitoring |
| 104 | + |
| 105 | +This deployment automatically configures **CloudWatch** log groups for enhanced observability: |
| 106 | + |
| 107 | +* 📄 **Lambda Function Execution Logs** |
| 108 | +* 🌐 **API Gateway Access Logs** |
| 109 | + |
| 110 | +Use the following options to inspect logs: |
| 111 | + |
| 112 | +* `--logs`: View recent logs for deployed resources |
| 113 | +* `--tail-logs`: Continuously stream logs in real-time |
| 114 | + |
| 115 | +These logs are crucial for debugging and monitoring your serverless application post-deployment. |
| 116 | + |
| 117 | + |
| 118 | +## 👨💻 Author |
| 119 | + |
| 120 | +Made with ❤️ by [@xanderbilla](https://www.github.com/xanderbilla) |
0 commit comments