In this project, we develop a set of AWS Lambda functions for a database-backed web application. The application uses REST APIs to handle interactions between the frontend and backend. The APIs are deployed on AWS using Lambda functions and API Gateway, with data stored in an RDS-backed database.
- getAllCategory: Fetch all categories from the database.
- getCategoryName: Retrieve the category name using the category ID.
- getCategoryId: Retrieve the category ID using the category name.
- addCategory: Add a new category with ID and name to the database.
- getAllBook: Fetch all books from the database.
- getBookById: Retrieve a book using the book ID.
- getBookByCategoryId: Retrieve books based on a given category ID.
- getBookByCategoryName: Retrieve books using a category name.
- getRandomBook: Fetch 5 random books from the database.
- addBook: Add a new book to the database.
The Lambda functions are deployed using AWS Lambda and are accessible through Amazon API Gateway. All data is transmitted in JSON format. The architecture ensures scalability and efficient resource utilization.
- Use AWS Lambda for serverless execution.
- Deploy shared dependencies as layers to optimize Lambda performance.
- Secure access using IAM roles and policies.
- Ensure logging for monitoring and debugging purposes.
- No sensitive information, such as access keys, should be hardcoded.
- Use AWS RDS for database management.
- Develop and test the solution locally before AWS deployment.
- Node.js as the primary programming language.
git clone https://github.com/your_username/aws-lambda-rest-api.git
cd aws-lambda-rest-apinpm installCreate a .env file to store database credentials:
DB_HOST=<your_db_host>
DB_USER=<your_db_user>
DB_PASSWORD=<your_db_password>
DB_NAME=<your_db_name>
Use tools like jest or Postman for testing API endpoints locally.
Use AWS SAM CLI or Serverless Framework for deployment.
sam build
sam deploy --guidedThe database consists of two primary tables:
-
Categories
category_id(Primary Key)category_name
-
Books
book_id(Primary Key)titleauthorcategory_id(Foreign Key)published_date
- Lambda execution roles with permissions to access RDS.
- API Gateway with appropriate access control.
curl -X GET "https://api.example.com/getBookById?id=123"{
"book_id": 123,
"title": "AWS for Beginners",
"author": "John Doe",
"category": "Cloud Computing",
"published_date": "2023-01-15"
}- AWS CloudWatch for tracking Lambda executions.
- Logs include request parameters, response payloads, and errors.
- Use IAM roles for granting minimal permissions.
- Avoid hardcoding sensitive information.
- Use environment variables for configuration.
This project is licensed under the MIT License.