Appearance
AWS ECS Deployment
Enterprise cloud deployment using ECS Fargate, RDS PostgreSQL, ElastiCache Redis, and ALB with WAF.
Architecture
Prerequisites
- AWS account with appropriate IAM permissions
- AWS CLI configured (
aws configure) - Terraform 1.5+ (for infrastructure)
- Docker (for building container images)
- ECR repository access
Infrastructure Setup
bash
# Deploy via the AWS target script
./infrastructure/scripts/targets/aws.sh upThis script orchestrates:
- Terraform -- provisions VPC, subnets, ALB, ECS cluster, RDS, ElastiCache, WAF
- ECR -- builds and pushes Docker images
- ECS -- creates task definitions and services
- Secrets Manager -- stores API keys and database credentials
Environment Configuration
AWS deployments use Secrets Manager and environment variables injected into ECS task definitions:
bash
# --- Provider ---
LLM_PROVIDER=openai
OPENAI_API_KEY=<from-secrets-manager>
DEFAULT_MODEL=gpt-4o-mini
# --- Database (RDS) ---
DATABASE_URL=postgresql://ghostai:<password>@<rds-endpoint>:5432/ghostai
# --- Cache (ElastiCache) ---
REDIS_URL=redis://<elasticache-endpoint>:6379/0
# --- PII ---
PII_ENABLE_AI_DETECTOR=true
PII_AI_MODEL=local
PII_REFEREE_RUNTIME=llama-cpp
PII_REFEREE_MODEL_GPU_LAYERS=0 # CPU on Fargate (no GPU)
PII_REFEREE_WARMUP=true
# --- URLs ---
BASE_URL=https://chat.yourdomain.com
FRONTEND_URL=https://chat.yourdomain.comGPU on Fargate
Standard ECS Fargate tasks do not have GPU access. For GPU-accelerated PII inference, either:
- Use
PII_REFEREE_RUNTIME=llama-cppwithGPU_LAYERS=0(CPU) - Run a separate vLLM service on EC2 GPU instances
Scaling
| Component | Scaling | Trigger |
|---|---|---|
| Backend tasks | Auto-scaling 2-10 | CPU > 70% or request count |
| Frontend tasks | Fixed 2 replicas | Static content, low resource |
| RDS | Vertical (instance size) | Connection count, IOPS |
| ElastiCache | Cluster mode sharding | Memory usage, connections |
Operations
bash
# Status
./infrastructure/scripts/targets/aws.sh status
# View logs (CloudWatch)
./infrastructure/scripts/targets/aws.sh logs
# Update (new image deploy)
./infrastructure/scripts/targets/aws.sh update
# Rollback to previous task definition
./infrastructure/scripts/targets/aws.sh rollback
# Validate health
./infrastructure/scripts/targets/aws.sh validateMonitoring
The AWS stress dashboard connects to CloudWatch for real-time metrics:
bash
python infrastructure/scripts/stress-dashboard.py --region us-east-1
# Monitors: ECS CPU/memory, RDS connections, ALB requests, WAF blocksSee Stress Test Dashboards for details.
Cost Estimates
| Component | Instance | Monthly (est.) |
|---|---|---|
| ECS Fargate (2 tasks) | 1 vCPU, 2 GB | ~$60 |
| RDS PostgreSQL | db.t4g.medium | ~$50 |
| ElastiCache Redis | cache.t4g.micro | ~$15 |
| ALB | Standard | ~$25 |
| NAT Gateway | Per-AZ | ~$35 |
| Total | ~$185/mo |
Scale up from there based on traffic. GPU instances for vLLM add ~$200-800/mo depending on instance type.