Skip to content

Task-4 : Added DynamoDB and Lambda Function for creating Product#2

Merged
Lunarr0 merged 5 commits intomainfrom
task-4
Mar 14, 2025
Merged

Task-4 : Added DynamoDB and Lambda Function for creating Product#2
Lunarr0 merged 5 commits intomainfrom
task-4

Conversation

@Lunarr0
Copy link
Owner

@Lunarr0 Lunarr0 commented Feb 27, 2025

Task 4 - AWS DynamoDB and Lambda Integration

Description

This PR implements Task 4 requirements, including creating and populating DynamoDB tables, extending the AWS CDK stack, integrating Lambda functions, and setting up API Gateway endpoints for interaction with the Product Service.

Implemented Features

✅ Task 4.1: Create DynamoDB Tables and Populate with Data

  • Created two DynamoDB tables: products and stocks.
  • Populated tables with test data using a script.
  • The script is available in the repository: link-to-script.

✅ Task 4.2: Extend AWS CDK Stack and Implement Lambda Functions

  • Extended the AWS CDK Stack with database table details.
  • Passed table details as environment variables to Lambda functions.
  • Implemented getProductsList Lambda to fetch products with stock information.
  • Implemented getProductsById Lambda to return a single product by ID.
  • Products and stocks are joined on product_id to provide a single unified response.
  • API Endpoints:
    • GET /products → [Invoke] (API-Gateway-URL-for-getProductsList)
    • GET /products/{productId} → [Invoke] (API-Gateway-URL-for-getProductsById)

✅ Task 4.3: Implement createProduct Lambda

  • Implemented createProduct Lambda to add new products.
  • The function handles adding a new product and its stock transactionally.
  • API Endpoint:
    • POST /products → [Invoke](API-Gateway-URL-for-createProduct)

✅ Task 4.4: Integration with Frontend Application

  • Integrated the /products API with the Frontend.
  • Products from the backend are displayed in the Frontend.
  • Live Frontend Application: [Link to frontend](Frontend-Deployment-URL)

Error Handling and Logging

  • 400 Status Code: Returns if product data is invalid during creation.
  • 500 Status Code: Handles unexpected errors gracefully.
  • Logging: All Lambda functions log incoming requests and their arguments.
  • Transactional Product Creation: Ensures that if stock creation fails, the related product is not created and vice versa.

How to Test

  1. Fetch all products

    curl -X GET https://pj8m5nmg5m.execute-api.us-east-1.amazonaws.com/prod/products/

    Response Example:

        {
           "description": "Organic plant-based protein.",
           "id": "e0c7c4c2-0e28-4b2e-8cbf-7a7344ca93ac",
           "price": 29,
           "title": "Vegan Protein Powder",
           "count": 10
       },
      {
         "description": "Organic plant-based protein.",
         "id": "123e4567-e89b-12d3-a456-426614174000",
         "price": 29,
         "title": "Vegan Protein Powder",
         "count": 50
        }
  2. Fetch product by ID

    curl -X GET https://pj8m5nmg5m.execute-api.us-east-1.amazonaws.com/prod/products/{productId}

    Response Example:

        {
           "description": "Organic plant-based protein.",
           "id": "e0c7c4c2-0e28-4b2e-8cbf-7a7344ca93ac",
           "price": 29,
           "title": "Vegan Protein Powder",
           "count": 10
       }
  3. Create a new product

    curl -X POST https://pj8m5nmg5m.execute-api.us-east-1.amazonaws.com/prod/products/
         -H "Content-Type: application/json" \
         -d '{"title": "New Product", "description": "Test Description", "price": 150, "count": 10}'

Submission Details

  • Backend PR: [Link to Backend PR](Backend-Repo-PR-URL)
  • Frontend PR : [Link to Frontend PR](Frontend-Repo-PR-URL)
  • Live API Gateway URLs for testing are provided above.
  • Cross-check reviewers can verify functionality using provided endpoints.

🚀 Ready for Review! Please let me know if you have any questions. 😊

@Lunarr0 Lunarr0 merged commit b6ce901 into main Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant