Skip to content

jobzz-kj/aws-bookapi

Repository files navigation

Project 3 – Implementation for REST API Endpoints using AWS Lambda

Description

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.

API Endpoints

  • 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.

Deployment Architecture

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.

Project Requirements

  • 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.

Setup Instructions

1. Clone the Repository

git clone https://github.com/your_username/aws-lambda-rest-api.git
cd aws-lambda-rest-api

2. Setup Node.js Environment

npm install

3. Environment Variables

Create 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>

4. Run Local Tests

Use tools like jest or Postman for testing API endpoints locally.

5. Deploy to AWS

Use AWS SAM CLI or Serverless Framework for deployment.

sam build
sam deploy --guided

Database Schema

The database consists of two primary tables:

  • Categories

    • category_id (Primary Key)
    • category_name
  • Books

    • book_id (Primary Key)
    • title
    • author
    • category_id (Foreign Key)
    • published_date

IAM Policies and Roles

  • Lambda execution roles with permissions to access RDS.
  • API Gateway with appropriate access control.

Sample API Request

GET /getBookById

curl -X GET "https://api.example.com/getBookById?id=123"

Sample Response

{
  "book_id": 123,
  "title": "AWS for Beginners",
  "author": "John Doe",
  "category": "Cloud Computing",
  "published_date": "2023-01-15"
}

Logs and Monitoring

  • AWS CloudWatch for tracking Lambda executions.
  • Logs include request parameters, response payloads, and errors.

Security Best Practices

  • Use IAM roles for granting minimal permissions.
  • Avoid hardcoding sensitive information.
  • Use environment variables for configuration.

License

This project is licensed under the MIT License.

About

Serverless REST API implementation using AWS Lambda, API Gateway, and RDS with Node.js for a database-backed application, supporting category and book operations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors