Skip to main content
This example uses the standalone cluster and service sub-modules to create a Fargate-based ECS deployment with blue/green deployment strategy and FireLens log forwarding.

What is created

  • ECS cluster (via modules/cluster) with Fargate and Fargate Spot capacity providers
  • ECS service (via modules/service) with:
    • FluentBit sidecar for log forwarding to Kinesis Firehose
    • Blue/green deployment with 2-minute bake time
    • ECS Exec enabled for debugging
    • ALB integration with two target groups
    • Service Connect
  • Application Load Balancer
  • VPC with 3 AZs

Code

module "ecs_cluster" {
  source = "terraform-aws-modules/ecs/aws//modules/cluster"

  name = local.name

  cluster_capacity_providers = ["FARGATE", "FARGATE_SPOT"]
  default_capacity_provider_strategy = {
    FARGATE = {
      weight = 50
      base   = 20
    }
    FARGATE_SPOT = {
      weight = 50
    }
  }

  tags = local.tags
}

Key highlights

  • Separate sub-modules: The cluster and service are managed independently. This allows teams to manage the cluster and services in separate Terraform workspaces.
  • Blue/green deployment: strategy = "BLUE_GREEN" with a 2-minute bake period before traffic shifts.
  • ECS Exec: enable_execute_command = true allows interactive shell access to running containers.
  • FireLens to Firehose: Logs are forwarded from FluentBit to a Kinesis Firehose delivery stream.

Complete Example

Full example with EC2 ASG, predictive autoscaling, and advanced ALB configuration.

Fargate Guide

Learn more about Fargate capacity provider configuration.