01 / 06
ECS on Fargate, not EC2
Fargate removes the entire 'who patches the box' question. You give it a container image and a task definition; it gives you a running process behind an ALB. Use EC2-backed ECS only when you need GPUs or specialized instance families.
hcl# main.tf (excerpt) resource "aws_ecs_task_definition" "web" { family = "app-web" network_mode = "awsvpc" requires_compatibilities = ["FARGATE"] cpu = "1024" memory = "2048" execution_role_arn = aws_iam_role.exec.arn container_definitions = jsonencode([{ name = "web" image = "${aws_ecr_repository.app.repository_url}:latest" portMappings = [{ containerPort = 3000 }] environment = [{ name = "RAILS_ENV", value = "production" }] secrets = [{ name = "RAILS_MASTER_KEY", valueFrom = aws_secretsmanager_secret.master_key.arn }] healthCheck = { command = ["CMD-SHELL", "curl -f localhost:3000/up || exit 1"] } }]) }