Skip to content

Serverless API for the Atithidev Website, powered by AWS Lambda. Designed for scalability, efficiency, and cost-effectiveness.

License

Notifications You must be signed in to change notification settings

ap-dev-github/atithidev-mongoose-api

 
 

Repository files navigation

Atithidev Serverless API 🌐

Overview 📝

This is a Serverless AWS Lambda Function-based API for the Atithidev Website. It provides endpoints to manage hosts and reviews using MongoDB Atlas as the database. The API is deployed using the Serverless Framework with CI/CD automation.

Features ✨

  • Fetch hosts and reviews 🗂️
  • Insert new reviews 📝
  • Fully serverless with AWS Lambda
  • Uses MongoDB Atlas as the database 🗄️
  • CI/CD automation with GitHub Actions 🤖
  • ESLint integration for code quality enforcement

CI/CD Integration 🤖

The project uses GitHub Actions for automated CI/CD pipelines, ensuring smooth and reliable deployments. Here's how it works:

CI/CD Workflow 🔄

  1. Trigger: 🚀 Pushing to the main branch triggers the CI/CD pipeline.
  2. Linting: ✅ ESLint runs to check code quality. If errors are found, the pipeline stops, and deployment is blocked.
  3. Dependency Installation: 📦 Only production dependencies (--production flag) are installed to optimize the deployment package.
  4. Deployment: 🚀 The Serverless Framework deploys the application to AWS Lambda if all checks pass.
  5. Secure Credentials: 🔐 AWS credentials (AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY) are securely managed using GitHub Secrets.

Benefits of CI/CD Automation:

  • Faster Deployments: 🚀 Automated pipelines reduce manual effort and speed up deployments.
  • Consistent Quality: ✅ ESLint ensures code quality is maintained across all deployments.
  • Secure Practices: 🔐 Sensitive credentials are never exposed in the codebase.

Security Features 🔒

  • AWS Secrets Management: 🔐 AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are securely stored in GitHub Secrets to prevent exposure in the codebase.
  • Environment Variables Protection: 🚫 The .env file is added to .gitignore to ensure sensitive information like MONGO_URI is not accidentally committed to the repository.
  • Code Quality Enforcement:ESLint is integrated into the CI/CD pipeline to enforce coding standards and prevent low-quality or insecure code from being deployed.
  • Least Privilege Principle: 🔑 AWS IAM roles are configured with minimal permissions required for the Lambda functions to interact with MongoDB Atlas and other AWS services.
  • Database Security: 🗄️ MongoDB Atlas is configured with IP whitelisting, encryption at rest, and network isolation to ensure data security.

Tech Stack 🛠️

  • Node.js (Runtime: 18.x) 🟢
  • Express.js (Lightweight API Framework) 🚀
  • MongoDB Atlas (Database) 🍃
  • AWS Lambda (Serverless Functions) ⚡
  • Serverless Framework (Deployment & CI/CD) 🛠️
  • GitHub Actions (CI/CD Pipeline) 🤖
  • ESLint (Code Quality) ✅

Setup Instructions 🛠️

1. Clone the Repository 📥

git clone https://github.com/ap-dev-github/atithidev-mongoose-api.git
cd atithidev-mongoose-api

2. Install Dependencies 📦

npm install

3. Environment Variables 🔐

Create a .env file in the root directory and add your MongoDB connection string:

MONGO_URI=your-mongodb-connection-string

Note: Make sure .env is added to .gitignore to prevent exposing secrets.

4. Run Locally with Serverless Offline 🖥️

npx serverless offline

This will start the API locally.

5. Deploy to AWS Lambda 🚀

npx serverless deploy

This will deploy the API to AWS.

Endpoints 🌐

Method Endpoint Description
GET / Home route, checks if API is running
GET /fetchHosts Fetch all hosts
GET /fetchHosts/:state Fetch hosts by state
GET /fetchHost/:id Fetch a host by ID
GET /fetchReviews/host/:id Fetch reviews for a specific host
POST /insert_review Insert a new review

Important Notes 📌

  • AWS Credentials: Set up AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as GitHub Secrets for CI/CD deployment.
  • MongoDB Connection: Ensure the MONGO_URI is correctly set in your .env file or AWS Lambda environment variables.
  • Serverless Framework: Install globally if not installed:
    npm install -g serverless
  • Linting: The project uses ESLint for code quality. Run:
    npx eslint .
    before deployment to check for issues.

License 📄

This project is licensed under the MIT License - see the LICENSE file for details.

Created & Maintained By 👨‍💻

Ayush Pandey | Contact: ayushpandey.cs@gmail.com 📧

LinkedIn: Ayush Pandey 🔗

About

Serverless API for the Atithidev Website, powered by AWS Lambda. Designed for scalability, efficiency, and cost-effectiveness.

Resources

License

Stars

Watchers

Forks

Packages

No packages published