A production-grade Pulumi Python project on AWS demonstrating ECS/Fargate + RDS Postgres with dev/staging/prod environments, WAF, CI/CD, unit testing, and policy as code.
graph TD
Internet -->|HTTP:80| ALB
subgraph VPC
ALB -->|HTTP:80| ECS["ECS Fargate (app)"]
ECS -->|TCP:5432| RDS["RDS Postgres"]
WAF -->|inspect| ALB
end
Internet --> WAF
Components:
- VPC with public/private subnets, NAT Gateway, Flow Logs
- ALB fronting ECS Fargate tasks
- RDS Postgres in private subnets (encrypted at rest)
- WAF WebACL (rate limiting + SQLi + common rules) — prod only
- ECR repository with lifecycle policy
- Pulumi CLI (free tier)
- AWS CLI configured with admin credentials
- Python 3.12+
- Docker
cd infrastructure
pulumi stack init dev
pulumi stack init staging
pulumi stack init prodpulumi config set --secret db_password <your-password> --stack dev
pulumi config set --secret db_password <your-password> --stack staging
pulumi config set --secret db_password <your-password> --stack prodCreate an IAM OIDC identity provider for GitHub and an IAM role with trust policy for your repo. See AWS docs.
Update the role-to-assume ARN in .github/workflows/preview.yml and .github/workflows/deploy.yml.
# Preview changes
make preview stack=dev
# Deploy
make up stack=dev
# Run tests (no AWS credentials needed)
make test
# Validate policy
make policy
# Destroy
make destroy stack=devUnit tests use pulumi.runtime.test — they validate resource specifications without provisioning anything. Run with:
make testCrossGuard policy in policies/ enforces:
- All resources must have an
Environmenttag
pulumi policy apply -C policies| Concern | Approach |
|---|---|
| State management | Pulumi Service (free tier) — no self-hosted state backend |
| Deployment model | Fargate (serverless) — no EC2 management |
| CI/CD auth | GitHub OIDC — no long-lived AWS keys |
| Secrets | Pulumi encrypted config — simple, no ESC dependency |
| Cost control | Dev/staging destroy-able; WAF only in prod |
- No blue/green deployments — out of scope for v1
- No ephemeral PR stacks — cost-prohibitive for personal AWS account
- No integration tests — require live infra; beyond demo scope
- NAT Gateway cost — ~$32/mo per environment; a nat-instance alternative was considered but not chosen for reliability
| Environment | Estimated Cost |
|---|---|
| Dev | ~$82 |
| Staging | ~$104 |
| Prod | ~$164 |
| All three | ~$350 |
Costs can be reduced by destroying non-active environments.
MIT