Skip to content

feat(task-8): Integration with RDS - #51

Open
SanjanaR-16 wants to merge 1 commit into
rolling-scopes-school:mainfrom
SanjanaR-16:task-8
Open

feat(task-8): Integration with RDS#51
SanjanaR-16 wants to merge 1 commit into
rolling-scopes-school:mainfrom
SanjanaR-16:task-8

Conversation

@SanjanaR-16

Copy link
Copy Markdown

Task 8 — NestJS Cart Service on AWS Lambda + RDS (PostgreSQL)


Task 8.1 — Lambda + API Gateway

  • Added src/lambda.ts — serverless entrypoint that bootstraps NestJS via @codegenie/serverless-express and exposes a handler for Lambda
  • Created infra/ — standalone CDK project (separate from the NestJS app) containing:
    • NodejsFunction (Node 20.x) pointing at src/lambda.ts
    • RestApi with a catch-all proxy LambdaIntegration routing all HTTP methods to the Lambda
  • Live API URL: https://jncym2xiu8.execute-api.us-east-1.amazonaws.com/prod/

Task 8.2 — RDS PostgreSQL + VPC + Security Groups

  • VPC with public + private subnets across 2 AZs with a NAT gateway for Lambda egress
  • DatabaseInstance using PostgresEngineVersion.VER_16_3, t3.micro, placed in private subnets
  • Dedicated security groups: Lambda SG → DB SG restricted to port 5432 only (least-privilege)
  • DB credentials auto-generated and stored in AWS Secrets Manager

Task 8.3 — TypeORM Cart + CartItem Models + DB Integration

Entities:

Table Columns
carts id UUID PK, user_id varchar not null, status enum (OPEN/ORDERED)
cart_items id UUID PK, cart_id FK → carts.id, product_id varchar not null, count int

Service changes:

  • CartService fully rewritten from in-memory storage to async TypeORM repository pattern
  • ProductCatalogService added — fetches product details from the product service by ID to preserve the { product, count } response shape expected by the frontend
  • Cart checkout transitions status to ORDERED instead of deleting the row

Environment variables:

  • DB connection details (DB_HOST, DB_PORT, DB_USER, DB_PASSWORD, DB_NAME, DB_SSL, DB_SYNC) injected into Lambda via CDK environment property
  • PRODUCT_SERVICE_URL configurable via CDK context flag -c productServiceUrl=...
  • Frontend apiPaths.ts updated to use the deployed cart API URL (overridable via VITE_CART_SERVICE_URL)

Link:SanjanaR-16/AWS_frontend#3

…entry, and separate CDK infra stack with VPC/RDS/API-Gateway
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