Deep DivesInfrastructure
Introduction
An overview of the RawStack Infrastructure component.
The Infrastructure component is an AWS CDK project written in TypeScript that defines and deploys the entire cloud environment for RawStack. It lives at infrastructure/aws/ and is the single source of truth for all AWS resources.
What it provisions
The CDK project is split into three stacks:
Core Stack
The backbone of the platform:
- VPC with public and private subnets across multiple AZs
- RDS PostgreSQL — the primary database, in a private subnet
- ElastiCache Redis — caching and token storage, in a private subnet
- ECS Fargate — runs the NestJS API as a containerised service
- Application Load Balancer — routes HTTPS traffic to Fargate tasks
- Auto-scaling — scales ECS tasks based on CPU and memory (1–10 tasks)
- EventBridge — receives CDK-deployed Lambda trigger for auto-deploys on ECR push
Web Stack
- ECS Fargate — runs the Next.js web app
- Application Load Balancer
- CloudFront CDN — caches static assets at the edge
Admin Stack
- S3 — hosts the static Admin SPA build
- CloudFront CDN — serves the admin dashboard globally
- Origin Access Control — only CloudFront can access the S3 bucket directly
Optional features
All stacks support optional custom domains. When domain variables are set, CDK provisions an ACM certificate and configures Route 53 DNS records automatically.