Skip to content

Task 8 - #52

Open
skyisnotmylimit wants to merge 5 commits into
rolling-scopes-school:mainfrom
skyisnotmylimit:task-8
Open

Task 8#52
skyisnotmylimit wants to merge 5 commits into
rolling-scopes-school:mainfrom
skyisnotmylimit:task-8

Conversation

@skyisnotmylimit

@skyisnotmylimit skyisnotmylimit commented May 29, 2026

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)

Deployement


…stgreSQL

- Created CDK project in infra/ directory
- Added Lambda function with NodejsFunction construct
- Configured API Gateway REST API with CORS support
- Added RDS PostgreSQL database instance in VPC
- Implemented TypeORM entities for Cart and CartItem models
- Added database configuration with AWS Secrets Manager support
- Updated CartService to use TypeORM repositories
- Configured environment variables for Lambda deployment

Task 8: AWS deployment infrastructure
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