# 🚀 Building a Scalable Serverless CRUD App with AWS

## **📋 Introduction**

Welcome to my comprehensive guide on building a **Serverless CRUD Application** using AWS! In this post, we'll dive deep into how to create and deploy a fully serverless, scalable, and cost-effective CRUD system using a variety of AWS services. Whether you're a developer eager to explore serverless architectures or looking for a rapid prototyping solution, this guide is for you! 😊

**Follow the GitHub Documentation and code for full implementation details:**  
🔹 [GitHub Repo: serverless-crud-app](https://github.com/prafulpatel16/serverless-crud-app)

---

## [Table of Contents](https://github.com/prafulpatel16/serverless-crud-app)

1. [About th](https://github.com/prafulpatel16/serverless-crud-app)[e Project](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#about-the-project)
    
2. [Architecture](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#architecture)
    
3. [Project Structure](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#project-structure)
    
4. [Prerequisites & Setup](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#prerequisites--setup)
    
5. [Documentations](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#documentations)
    
6. [Detailed Workflow](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#detailed-workflow)
    
7. [CRUD Operations](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#crud-operations)
    
8. [Deployment & Configuration](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#deployment--configuration)
    
9. [Local Testing](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#local-testing)
    
10. [AWS Services Used](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#aws-services-used)
    
11. [Contributing](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#contributing)
    
12. [License](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#license)
    
13. [Author](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#author)
    
14. [Additional Resources](https://chatgpt.com/c/67ba60ff-a6b4-8011-bb41-ed1aac85eb9f#additional-resources)
    

---

## About the Project 📝

The **Serverless CRUD App** is a complete backend and frontend solution that leverages a fully serverless architecture to manage Create, Read, Update, and Delete operations. Built with AWS SAM, CloudFormation, and a structured backend API, this project seamlessly integrates with a simple HTML/JavaScript frontend hosted on Amazon S3.

**Why build a Serverless CRUD App?**

* **Scalability:** Automatically scales based on demand.
    
* **Cost-Effective:** Pay only for what you use.
    
* **Simplicity:** Focus on business logic instead of server maintenance.
    
* **High Availability:** AWS services ensure robust, fault-tolerant operations.
    

**When is this useful?**

* Rapid prototyping of applications.
    
* Developing low to medium traffic apps.
    
* Optimizing costs for intermittent workloads.
    

---

## Architectural Flow🏗️

The app is built on a modern AWS serverless stack. Here's an architectural overview:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740875487636/fc09ef64-1ef6-43a8-bd05-9760a7646318.jpeg align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740875559929/ff175795-69c1-481d-a432-670950a73610.jpeg align="center")

### Key Components:

* **Frontend (S3):** Hosts the static HTML, CSS, and JS.
    
* **API Gateway:** Exposes RESTful endpoints for CRUD operations.
    
* **Lambda Functions:** Execute CRUD logic and handle API requests.
    
* **DynamoDB:** NoSQL database storing items (e.g., `id`, `name`, `age`).
    

Frontend UI

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1740875970134/21122c9c-5d78-4dfe-980c-9bdac3f49f6f.png align="center")

---

## Project Structure 📁

```plaintext
serverless-crud-app/
├── backend/
│   ├── create/         # Lambda function for creating resources
│   ├── read/           # Lambda function for reading a single resource
│   ├── update/         # Lambda function for updating resources
│   ├── delete/         # Lambda function for deleting resources
│   ├── list/           # Lambda function for listing resources
│   └── documentations/ # Detailed API and infrastructure docs
├── frontend/
│   └── index.html      # Static frontend UI
├── pipelines/          # CI/CD pipeline configurations
├── cloudformation.yaml # CloudFormation/SAM stack configuration
├── template.yaml       # AWS SAM template definition
└── README.md           # Project documentation
```

* **backend/**: Contains all Lambda function code and documentation.
    
* **frontend/**: Hosts the static UI assets.
    
* **pipelines/**: Holds configurations for automated CI/CD deployments.
    
* **cloudformation.yaml / template.yaml**: Define the AWS infrastructure as code.
    
* **README.md**: Provides an overview and detailed documentation for the project.
    

---

## Prerequisites & Setup 🛠️

Before you begin, ensure you have:

* **AWS Account:** Required to deploy AWS resources.
    
* **AWS CLI:** [Installation Guide](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) and configure with `aws configure`.
    
* **AWS SAM CLI / CloudFormation:** For packaging and deploying the serverless application.
    
* **Node.js / Python:** For frontend and backend development/testing.
    

---

## Documentations 📜

Additional documentation files can be found in the `documentations/` directory:

* [0.0 Pre-requisite](https://chatgpt.com/c/documentations/0.0.pre-requisite.md)
    
* [0.1 IAM Roles](https://chatgpt.com/c/documentations/0.1.IAM-roles.md)
    
* [1\. API Documentation](https://chatgpt.com/c/documentations/1.API-document.md)
    
* [2\. API Testing](https://chatgpt.com/c/documentations/2.Api-testing.md)
    
* [3\. App Functionality](https://chatgpt.com/c/documentations/3.app-functionality.md)
    
* [4\. Frontend Documentation](https://chatgpt.com/c/documentations/4.frontend-doc.md)
    
* [5\. SAM Infra Documentation](https://chatgpt.com/c/documentations/5.sam-infra-documentation.md)
    

---

## Detailed Workflow 🔄

1. **User Accesses the Frontend:**  
    The user opens the static site hosted on Amazon S3 (optionally via CloudFront).
    
2. **User Chooses a CRUD Operation:**
    
    * **Create:** Fill out ID, Name, and Age fields.
        
    * **Read:** Enter an ID to fetch details.
        
    * **Update:** Enter an ID along with fields to update.
        
    * **Delete:** Enter an ID to remove an item.
        
    * **List:** Retrieve all items from the DynamoDB table.
        
3. **Request Routing via API Gateway:**  
    The frontend sends an HTTP request to API Gateway, which routes it to the appropriate Lambda function.
    
4. **Lambda Function Processing:**  
    The Lambda function performs the CRUD operation on the DynamoDB table and returns a JSON response.
    
5. **Response Displayed on the Frontend:**  
    The result (success or error) is displayed to the user in the UI.
    

---

## CRUD Operations ⚙️

1. **Create (POST /create):**
    
    * **Frontend:** Sends an array of items (e.g., `[{ id, name, age }, ...]`).
        
    * **Lambda:** Inserts each item into DynamoDB using `put_item`.
        
2. **Read (GET /read?id=123):**
    
    * **Frontend:** Appends `?id=123` to the URL.
        
    * **Lambda:** Retrieves an item using `get_item(Key={"id": ...})`.
        
3. **Update (PUT /update):**
    
    * **Frontend:** Sends a JSON payload with `id` and fields to update.
        
    * **Lambda:** Uses `update_item` with dynamic update expressions.
        
4. **Delete (DELETE /delete):**
    
    * **Frontend:** Sends a JSON payload with `"Key": { "id": "..." }`.
        
    * **Lambda:** Calls `delete_item(Key={"id": ...})`.
        
5. **List (GET /list):**
    
    * **Frontend:** Issues a GET request to retrieve all items.
        
    * **Lambda:** Scans or queries the DynamoDB table to list items.
        

---

## Deployment & Configuration 🚀

1. **CloudFormation / AWS SAM:**  
    Run:
    
    ```sh
    sam build && sam deploy --guided
    ```
    
    This command deploys your backend resources, including Lambda functions, DynamoDB, and API Gateway.
    
2. **S3 Frontend Hosting:**
    
    * Upload your `frontend/index.html` (and assets) to an S3 bucket.
        
    * Enable **Static Website Hosting** on the bucket.
        
    * Optionally, configure **CloudFront** for better global distribution.
        
3. **Environment Variables:**  
    Set `TABLE_NAME` in your Lambda configuration to the name of your DynamoDB table.
    
4. **CORS Configuration:**  
    Ensure each Lambda response includes `Access-Control-Allow-Origin: *`. API Gateway should be configured with Lambda Proxy Integration to pass these headers through.
    

---

## AWS Services Used 🌐

This project leverages several key AWS services:

* **AWS S3:** For hosting the static frontend.
    
* **Amazon API Gateway:** To expose RESTful endpoints.
    
* **AWS Lambda:** For executing backend CRUD logic.
    
* **AWS CloudFormation / SAM:** For defining and deploying infrastructure as code.
    
* **Amazon DynamoDB:** As a scalable NoSQL database.
    
* **AWS CloudWatch:** For logging and monitoring.
    
* **AWS X-Ray:** For tracing and debugging Lambda invocations.
    
* **AWS IAM:** To securely manage permissions and roles.
    
* **AWS CloudFront:** For global content delivery (optional).
    
* **AWS Cognito:** (Optional) For user authentication and authorization if needed.  
    POSTMAN
    

---

## Features ✨

* **🛠️ Serverless Backend:** Leverages AWS Lambda to handle CRUD operations.
    
* **📜 Infrastructure as Code:** Built with AWS SAM and CloudFormation templates.
    
* **🎨 Modern Frontend UI:** A simple HTML/JavaScript interface for interacting with the backend.
    
* **🚀 CI/CD Pipelines:** Automated deployments via AWS CodePipeline or GitHub Actions.
    
* **📖 Comprehensive Documentation:** Detailed API docs, testing guides, and architecture overviews.
    

---

## Local Testing 🧪

1. **Using Postman:**
    
    * **Create:** `POST /create` with JSON body: `{"items": [{"id":"123","name":"Test","age":25}]}`
        
    * **Read:** `GET /read?id=123`
        
    * **Update:** `PUT /update` with JSON body: `{"id":"123","name":"NewName","age":30}`
        
    * **Delete:** `DELETE /delete` with JSON body: `{"Key":{"id":"123"}}`
        
    * **List:** `GET /list`
        
2. **CloudWatch Logs:**  
    Use CloudWatch to monitor Lambda logs and debug issues.
    

---

## Contributing 🤝

Contributions are welcome! Here’s how you can contribute:

1. **Fork & Clone:** Fork the repository on GitHub and clone it locally.
    
2. **Create a Feature Branch:**
    
    ```sh
    git checkout -b feature/my-awesome-feature
    ```
    
3. **Commit & Push:** Make your changes, commit, and push them to your fork.
    
4. **Open a Pull Request:** Provide detailed descriptions of your changes and open a PR against the `main` branch.
    

For additional guidelines, please refer to the [CONTRIBUTING.md](https://chatgpt.com/c/documentations/CONTRIBUTING.md) file.

---

## License 📄

This project is licensed under the [MIT License](https://chatgpt.com/c/LICENSE).

---

## Author 👨‍💻

Created and maintained by **Praful Patel**.

* [Praful's GitHub](https://github.com/prafulpatel16)
    
* [Praful's Blog](https://www.praful.cloud/)
    

---

## Additional Resources 📚

* [AWS Lambda Documentation](https://docs.aws.amazon.com/lambda/)
    
* [Amazon API Gateway Documentation](https://docs.aws.amazon.com/apigateway/)
    
* [Amazon DynamoDB Documentation](https://docs.aws.amazon.com/dynamodb/)
    
* [AWS SAM Documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html)
    

---

**Happy Building!**  
If you have any questions or need further details, feel free to open an issue on GitHub or reach out directly.
