{"id":25019574,"url":"https://github.com/iambotcoder/serverless-crud-api","last_synced_at":"2026-02-04T07:32:01.943Z","repository":{"id":272411182,"uuid":"916377845","full_name":"iambotcoder/serverless-crud-api","owner":"iambotcoder","description":"A serverless CRUD API leveraging AWS Lambda, API Gateway, and DynamoDB for seamless and scalable database operations.","archived":false,"fork":false,"pushed_at":"2025-02-20T17:06:54.000Z","size":30,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-20T18:23:07.102Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iambotcoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-14T01:16:00.000Z","updated_at":"2025-02-20T17:06:58.000Z","dependencies_parsed_at":"2025-01-14T09:33:28.444Z","dependency_job_id":"f49b97a9-30f1-46a0-acd7-336972131399","html_url":"https://github.com/iambotcoder/serverless-crud-api","commit_stats":null,"previous_names":["iambotcoder/serverless-crud-ap"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iambotcoder%2Fserverless-crud-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iambotcoder%2Fserverless-crud-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iambotcoder%2Fserverless-crud-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iambotcoder%2Fserverless-crud-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iambotcoder","download_url":"https://codeload.github.com/iambotcoder/serverless-crud-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246301997,"owners_count":20755514,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-05T11:51:04.115Z","updated_at":"2026-02-04T07:31:56.711Z","avatar_url":"https://github.com/iambotcoder.png","language":null,"readme":"# 🌐 Lambda API Gateway Integration with DynamoDB 🚀\n---\n\n## 📖 Introduction\n\nThis project demonstrates the implementation of a serverless API using **AWS services** such as **API Gateway**, **Lambda**, and **DynamoDB**. It showcases how to build a backend system without managing servers, utilizing these components to handle HTTP requests, execute backend logic, and interact with a NoSQL database. \n\nThe key components of this project are:\n- **API Gateway**: Acts as an HTTP interface for accessing Lambda functions. 🌐\n- **AWS Lambda**: Runs backend logic for processing API requests. 🧑‍💻\n- **DynamoDB**: Serves as the NoSQL database for storing and retrieving data. 📊\n\n---\n\n## 📑 Table of Contents\n- [Overview](#overview)\n- [Prerequisites](#Prerequisites) 🔑\n- [Architecture Diagram](#architecture-diagram) 🏗️\n- [Implementation Steps](#implementation-steps) 🔨\n  - [Step 1: Create IAM Policy and Role](#step-1-create-iam-policy-and-role) 🛠️\n  - [Step 2: Deploy the Lambda Function](#step-2-deploy-the-lambda-function) 🚀\n  - [Step 3: Configure API Gateway](#step-3-configure-api-gateway) ⚙️\n  - [Step 4: Test the Solution with Postman](#step-4-test-the-solution-with-postman) 🧪\n- [Screenshots](#screenshots) 📸\n- [Conclusion](#conclusion) ✅\n\n---\n\n## 🔑 Prerequisites\nBefore you start, ensure you have the following:\n- An AWS account 🌍\n- Basic knowledge of AWS services: Lambda, API Gateway, and DynamoDB 📚\n- Installed tools: [Postman](https://www.postman.com/) 🔧\n\n---\n\n## 🏗️ Architecture Diagram\nProvide a high-level architecture diagram of the project setup.  \n![Architecture Diagram](https://github.com/user-attachments/assets/f4dffa5b-22d1-4ec9-a004-5958b36215ab)\n\n---\n\n### 🛠️ Supported Operations\nThe API supports the following operations:\n- **DynamoDB CRUD Operations**:\n  - `create`, `read`, `update`, `delete`, `list` 🔄\n- **Testing Operations**:\n  - `echo` (returns the input as-is) 🔊\n  - `ping` (returns \"pong\") 🏓\n\n---\n\n### ⚙️ Steps to Implement\n\n### 1️⃣ Setup: IAM Role Creation\n- **Create an IAM Role (lambda-apigateway-role):**\n  1. Go to the AWS Management Console and navigate to the **IAM** service. 🛡️\n  2. Create a new policy with the following JSON 📝\n  3. Attach the following custom policy JSON to provide necessary permissions:\n     ```json\n      {\n      \"Version\": \"2012-10-17\",\n      \"Statement\": [\n      {\n        \"Sid\": \"Stmt1428341300017\",\n        \"Action\": [\n          \"dynamodb:DeleteItem\",\n          \"dynamodb:GetItem\",\n          \"dynamodb:PutItem\",\n          \"dynamodb:Query\",\n          \"dynamodb:Scan\",\n          \"dynamodb:UpdateItem\"\n        ],\n        \"Effect\": \"Allow\",\n        \"Resource\": \"*\"\n      },\n      {\n        \"Sid\": \"\",\n        \"Resource\": \"*\",\n        \"Action\": [\n          \"logs:CreateLogGroup\",\n          \"logs:CreateLogStream\",\n          \"logs:PutLogEvents\"\n        ],\n        \"Effect\": \"Allow\"\n      }\n      ]\n      }\n     ```\n  4. Save the policy with the name **lambda-apigateway-policy**. 💾\n  5. Go to the Roles section in IAM and create a new role. 🎭\n  6. Attach the **lambda-apigateway-policy** to the role. 🔑\n\n---\n\n### 2️⃣ Create Lambda Function\n- **Lambda Function (LambdaFunctionOverHttps):**\n  1. Go to the **AWS Lambda** console and click on **Create Function**. 🆕\n  2. Choose the following settings:\n     - **Author from scratch**: Yes. 📝\n     - **Runtime**: Python 3.13 or a newer supported version as the runtime. 🐍\n     - **Execution Role**: Use the previously created `lambda-apigateway-role`. 🎭\n  3. Use the following Python code snippet for the function:\n     ```python\n     from __future__ import print_function\n\n      import boto3\n      import json\n     \n      print('Loading function')\n\n      def lambda_handler(event, context):\n          operation = event['operation']\n\n      if 'tableName' in event:\n          dynamo = boto3.resource('dynamodb').Table(event['tableName'])\n\n      operations = {\n          'create': lambda x: dynamo.put_item(**x),\n          'read': lambda x: dynamo.get_item(**x),\n          'update': lambda x: dynamo.update_item(**x),\n          'delete': lambda x: dynamo.delete_item(**x),\n          'list': lambda x: dynamo.scan(**x),\n          'echo': lambda x: x,\n          'ping': lambda x: 'pong'\n      }\n\n      if operation in operations:\n          return operations[operation](event.get('payload'))\n      else:\n          raise ValueError('Unrecognized operation \"{}\"'.format(operation))\n     ```\n  4. Save and deploy the function. 🚀\n\n---\n\n### 3️⃣ Test Lambda Function\n- Test the Lambda function using the **echo** operation:\n  - Sample test event JSON:\n    ```json\n    {\n      \"operation\": \"echo\",\n        \"payload\": {\n          \"somekey1\": \"somevalue1\",\n          \"somekey2\": \"somevalue2\"\n      }\n    }\n    ```\n  - Expected output:\n    ```json\n    {\n      \"somekey1\": \"somevalue1\",\n      \"somekey2\": \"somevalue2\"\n    }\n    ```\n\n---\n\n### 4️⃣ Create DynamoDB Table\n- **DynamoDB Table (lambda-apigateway):**\n  1. Go to the **DynamoDB** console and click on **Create Table**. 📊\n  2. Set the table name to `lambda-apigateway`. 🏷️\n  3. Define the **Primary Key**:\n     - Partition Key: `id` (String). 🔑\n\n---\n\n### 5️⃣ Create API Gateway\n- **API Gateway Setup:**\n  1. Navigate to **API Gateway**, choose REST API and create a new API: 🎛️\n     - Name: `DynamoDBOperations`. 💬\n  2. Add a new resource:\n     - Resource Name: `DynamoDBManager`. 🗂️\n  3. Add a method to the resource:\n     - Method: `POST`. 📨\n  4. Integrate the POST method with the Lambda function:\n     - Select **Lambda Function** as the integration type. 🔗\n     - Specify the function name (`LambdaFunctionOverHttps`). 🖥️\n\n---\n\n### 6️⃣ Deploy API\n- **Deploy the API:**\n  1. Go to the **Actions** menu and select **Deploy API**. 🏁\n  2. Create a new stage: `prod`. 🚀\n  3. Retrieve the **Invoke URL** for the deployed API. 🌐\n\n---\n\n## 🧪 Running the Solution with Postman\n  1. Open Postman and create a new request with the following configurations:\n       - HTTP Method: POST ✉️\n       - URL: `\u003cAPI Gateway Invoke URL\u003e/DynamoDBManager` 🌍\n  2. Test different scenarios using the following payloads:\n\n  - **Create Operation** 💾\n    ```json\n    {\n        \"operation\": \"create\",\n        \"tableName\": \"lambda-apigateway\",\n        \"payload\": {\n            \"Item\": {\n                \"id\": \"123\",\n                \"value\": \"sample data\"\n            }\n        }\n    }\n    ```\n\n  - Outcome 🎉  \n    ![Screenshot 2025-01-14 050636](https://github.com/user-attachments/assets/f86899d4-ac95-4d20-b0b6-8cddd11d45b0)\n\n  - **Read Operation** 📚\n    ```json\n    {\n      \"operation\": \"read\",\n      \"tableName\": \"lambda-apigateway\",\n      \"payload\": {\n            \"Key\": {\n              \"id\": \"123\"\n          }\n      }\n    }\n    ```\n    ![Screenshot 2025-01-14 050652](https://github.com/user-attachments/assets/fec0ba19-ff73-419f-8312-4200847d40ab)\n\n  \n  - **Update Operation** ✏️\n  ```json\n      {\n        \"operation\": \"update\",\n        \"tableName\": \"lambda-apigateway\",\n        \"payload\": {\n              \"Key\": {\n                  \"id\": \"56789ABCD\"\n            },\n            \"UpdateExpression\": \"set #num = :val1\",\n            \"ExpressionAttributeValues\": {\n                \":val1\": 42\n            },\n            \"ExpressionAttributeNames\": {\n                \"#num\": \"number\"\n            },\n            \"ReturnValues\": \"UPDATED_NEW\"\n        }\n    }\n\n```\n\n  - outcome ✅\n  ![Screenshot 2025-01-14 053219](https://github.com/user-attachments/assets/4f00bee4-95d8-41b2-9833-851ce6114803)\n\n  - Delete Operation\n  ```json\n    {\n      \"operation\": \"delete\",\n      \"tableName\": \"lambda-apigateway\",\n      \"payload\": {\n            \"Key\": {\n                \"id\": \"56789ABCD\"\n          }\n      }\n    }\n  ```\n  - outcome 🏁\n  ![Screenshot 2025-01-14 052910](https://github.com/user-attachments/assets/281cf0de-a4e3-4a4b-879b-a2420e7e6cf6)\n\n- Verify the results in the DynamoDB console. 📊\n\n---\n### Cleanup\n- Delete the created resources to avoid unnecessary costs:\n  1. DynamoDB table.📅\n  2. Lambda function.🔌\n  3. API Gateway resources.🚫\n\n---\n### ✅ Conclusion\nThis guide demonstrates how to integrate AWS Lambda with API Gateway and DynamoDB to perform database operations in a serverless architecture. It provides a scalable and efficient approach to manage CRUD functionalities with minimal infrastructure management.\n\n## 👨‍🏫 Instructor\n\nThis project was guided by **Rajdeep Saha**, who provided valuable mentorship throughout the process.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiambotcoder%2Fserverless-crud-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiambotcoder%2Fserverless-crud-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiambotcoder%2Fserverless-crud-api/lists"}