Skip to main content

Command Palette

Search for a command to run...

πŸš€ Building a Scalable Serverless CRUD App with AWS

Updated
β€’6 min read
πŸš€ Building a Scalable Serverless CRUD App with AWS
P

PRAFUL PATEL β˜οΈπŸš€, Highly skilled and motivated Cloud Engineer with a proven track record of designing, implementing, and managing robust cloud infrastructure solutions. With years of hands-on experience, I am deeply passionate about creating scalable and resilient cloud architectures that drive innovation and deliver optimal business outcomes. πŸ›  Key Competencies:

Cloud Platforms: AWS, Azure, GCP, OCI Infrastructure as Code: Terraform, Ansible Containers & Orchestration: Docker, Kubernetes Scripting: Python, Bash/Shell CI/CD & Version Control: GitHub, Jenkins, CircleCI Monitoring & Analytics: Grafana, Prometheus, Datadog, New Relic Backup & Recovery: Veeam Operating Systems: Linux, Windows DevOps Tools: AWS Code Build, Code Pipeline, Azure DevOps

πŸ“š Continuous Learning: Staying ahead in the rapidly evolving cloud landscape is my priority. I am committed to expanding my skill set and embracing emerging cloud technologies to drive efficiency and innovation. Passionate Cloud/DevOps enthusiast dedicated to designing, building, and deploying cutting-edge technology solutions. As a devoted YouTuber, I love sharing insights through informative videos and crafting technical blogs that delve into areas like ☁️ Cloud, πŸ› οΈ DevOps, 🐧 Linux, and πŸ“¦ Containers. πŸ’» Open Source Advocate: Contributing to open-source projects is a vital part of my journey. I actively engage in projects centered around Cloud, DevOps, Linux, and Containers, fostering collaboration and innovation within the community. πŸ’Œ Let's Connect: I am enthusiastic about virtual collaborations and meeting fellow professionals. Let's explore how I can contribute to your organization's cloud goals. Feel free to connect or DM me.

🌐 Portfolio: Check out my portfolio πŸ”— LinkedIn: Connect on LinkedIn πŸ› οΈ GitHub: Explore my projects πŸŽ₯ YouTube: Watch my videos πŸ“ Medium: Read my articles 🌐 Dev.to: Check out my posts

πŸ“‹ 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


Table of Contents

  1. About the Project

  2. Architecture

  3. Project Structure

  4. Prerequisites & Setup

  5. Documentations

  6. Detailed Workflow

  7. CRUD Operations

  8. Deployment & Configuration

  9. Local Testing

  10. AWS Services Used

  11. Contributing

  12. License

  13. Author

  14. 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:

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


Project Structure πŸ“

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


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:

     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:

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


License πŸ“„

This project is licensed under the MIT License.


Author πŸ‘¨β€πŸ’»

Created and maintained by Praful Patel.


Additional Resources πŸ“š


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

More from this blog

C

cloud/devops

29 posts

PRAFUL PATEL β˜οΈπŸš€, Highly skilled and motivated Cloud/DevOps Engineer with a proven track record of designing, implementing, and managing robust cloud infrastructure solutions.