Skip to content

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 up

This script orchestrates:

  1. Terraform -- provisions VPC, subnets, ALB, ECS cluster, RDS, ElastiCache, WAF
  2. ECR -- builds and pushes Docker images
  3. ECS -- creates task definitions and services
  4. 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.com

GPU on Fargate

Standard ECS Fargate tasks do not have GPU access. For GPU-accelerated PII inference, either:

  • Use PII_REFEREE_RUNTIME=llama-cpp with GPU_LAYERS=0 (CPU)
  • Run a separate vLLM service on EC2 GPU instances

Scaling ​

ComponentScalingTrigger
Backend tasksAuto-scaling 2-10CPU > 70% or request count
Frontend tasksFixed 2 replicasStatic content, low resource
RDSVertical (instance size)Connection count, IOPS
ElastiCacheCluster mode shardingMemory 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 validate

Monitoring ​

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 blocks

See Stress Test Dashboards for details.

Cost Estimates ​

ComponentInstanceMonthly (est.)
ECS Fargate (2 tasks)1 vCPU, 2 GB~$60
RDS PostgreSQLdb.t4g.medium~$50
ElastiCache Rediscache.t4g.micro~$15
ALBStandard~$25
NAT GatewayPer-AZ~$35
Total~$185/mo

Scale up from there based on traffic. GPU instances for vLLM add ~$200-800/mo depending on instance type.

SOC 2 Type II Certified | BAA Available | HIPAA-Ready