A serverless RESTful API for course management built with Spring Boot and AWS Lambda. This application allows you to create, read, update, and delete course information through a simple REST interface, all running on AWS's serverless infrastructure.
- Architecture
- Features
- API Endpoints
- Prerequisites
- Getting Started
- Local Development
- Deployment
- Technologies Used
This application follows a serverless architecture pattern:
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ │ │ │ │ │
│ API │────▶│ AWS │────▶│ Spring │
│ Gateway │ │ Lambda │ │ Boot App │
│ │ │ │ │ │
└─────────────┘ └─────────────┘ └─────────────┘
- API Gateway: Routes HTTP requests to the Lambda function
- AWS Lambda: Executes the Spring Boot application in a serverless environment
- Spring Boot: Handles business logic and provides REST endpoints
The application uses the AWS Serverless Java Container library to bridge Spring Boot with AWS Lambda, allowing a standard Spring Boot application to run efficiently in a serverless environment.
- Course Management: Create, read, update, and delete course information
- RESTful API: Standard HTTP methods for interacting with resources
- Serverless Architecture: No server management required, scales automatically
- Low Cost: Pay only for what you use with AWS Lambda's pricing model
| Method | Endpoint | Description | Request Body | Response |
|---|---|---|---|---|
| GET | /ping | Health check endpoint | - | {"pong": "Hello, World!"} |
| GET | /courses | Get all courses | - | Array of Course objects |
| GET | /courses/{id} | Get course by ID | - | Course object or 404 |
| POST | /courses | Create a new course | Course object | Created Course object |
| PUT | /courses/{id} | Update an existing course | Course object | 200 OK or 404 Not Found |
| DELETE | /courses/{id} | Delete a course | - | 200 OK or 404 Not Found |
{
"id": 1,
"name": "Introduction to AWS Lambda",
"price": 99.99
}- AWS CLI - Configured with appropriate permissions
- SAM CLI - For local testing and deployment
- Java 17 - Required for development
- Maven - For building the project
-
Clone the repository:
git clone https://github.com/yourusername/aws-lambda-example.git cd aws-lambda-example -
Build the project:
mvn clean package
You can test the application locally using the SAM CLI:
-
Build the application:
sam build
-
Start the local API:
sam local start-api -
Test the API:
# Test the ping endpoint curl -s http://127.0.0.1:3000/ping | python -m json.tool # Get all courses curl -s http://127.0.0.1:3000/courses | python -m json.tool # Create a new course curl -s -X POST http://127.0.0.1:3000/courses \ -H "Content-Type: application/json" \ -d '{"name":"AWS Lambda Masterclass","price":149.99}' | python -m json.tool
Deploy the application to AWS using the SAM CLI:
sam deploy --guidedFollow the prompts to configure your deployment. Once deployed, SAM will output the API Gateway URL that you can use to access your application.
Example:
-------------------------------------------------------------------------------------------------------------
OutputKey-Description OutputValue
-------------------------------------------------------------------------------------------------------------
AwsLambdaExampleApi - URL for application https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/Prod/
-------------------------------------------------------------------------------------------------------------
- Spring Boot 3: Java framework for building web applications
- AWS Lambda: Serverless compute service
- AWS API Gateway: Managed service for creating, publishing, and securing APIs
- AWS SAM: Serverless Application Model for easier deployment
- Java 17: Programming language
- Maven: Build and dependency management
- Lombok: Reduces boilerplate code
Built with ❤️ using AWS Serverless Java Container