flag92 flag92
Deploy

Chatwoot + Dify on AWS ECS Fargate

Serverless containers for AI support — no EC2, pay per resource. Terraform module, auto-scaling and cost control.

AWS ECS Fargate + RDS + ElastiCache 180 min

Why Fargate#

  • No EC2 ops; pay per vCPU + GB-second
  • Auto-scales; near-zero cost when idle
  • 30-50% more expensive than self-managed EC2 — pick it for ops simplicity

Architecture#

ALB · Public

ECS Cluster · Fargate

chatwoot-rails
2-10 tasks

chatwoot-sidekiq
1-5 tasks

dify-api
2-10 tasks

dify-worker
1-5 tasks

RDS PostgreSQL
Multi-AZ

ElastiCache Redis

S3 · attachments

Terraform skeleton#

module "ecs" {
  source = "terraform-aws-modules/ecs/aws"
  cluster_name = "ai-support"

  fargate_capacity_providers = {
    FARGATE      = { default_capacity_provider_strategy = { weight = 50 } }
    FARGATE_SPOT = { default_capacity_provider_strategy = { weight = 50 } }
  }
}

resource "aws_ecs_service" "chatwoot" {
  name            = "chatwoot-rails"
  cluster         = module.ecs.cluster_id
  task_definition = aws_ecs_task_definition.chatwoot.arn
  desired_count   = 2
  launch_type     = "FARGATE"
}

resource "aws_appautoscaling_target" "chatwoot" {
  max_capacity       = 10
  min_capacity       = 2
  resource_id        = "service/${module.ecs.cluster_name}/chatwoot-rails"
  scalable_dimension = "ecs:service:DesiredCount"
  service_namespace  = "ecs"
}

Costs#

ResourceSpecMonthly
Fargate per task0.5 vCPU / 1 GB~$15
Fargate Spot discount-50%
RDS PG db.t3.medium~$80
ElastiCache r6g.large~$80
ALB~$20
S3 + traffic~$30
Typical mid prod~$300/mo

Running 50% on Fargate Spot saves 25-40%.

Auto-scaling#

TargetTrackingScalingPolicy:
  TargetValue: 70
  PredefinedMetricSpecification:
    PredefinedMetricType: ECSServiceAverageCPUUtilization

Three AWS-specific gotchas#

  1. Cold starts — Fargate tasks take 30-60s to launch; pre-warm before promo traffic
  2. Spot interruption — Fargate Spot can be reclaimed with 2-minute notice; handle SIGTERM gracefully
  3. NAT Gateway cost — private subnet egress to LLM is billed per GB; use VPC Endpoints / PrivateLink at scale

Search

Press ⌘ K to open