Amazon ECS

A fully managed container orchestration service for deploying, managing, and scaling Docker containers, offering both Fargate and EC2 launch types

Overview

Amazon Elastic Container Service (ECS) is a fully managed container orchestration service for running and managing Docker containers at scale. Task definitions declaratively specify container images, CPU/memory requirements, network settings, log configuration, and more. Deploying as a service ensures that the specified number of tasks is always running. The Fargate launch type eliminates infrastructure management, while the EC2 launch type provides fine-grained control over instances. ECS integrates with ALB and NLB for traffic distribution, Auto Scaling for automatic task count adjustment, ECR (Elastic Container Registry) for container image retrieval, and CloudWatch for monitoring and log management. ECS Exec allows you to connect directly to running containers for debugging.

Task Definitions and the Sidecar Pattern

An ECS task definition is a JSON template that defines how one or more containers should run. Each container is configured with an image URI, CPU/memory allocation, port mappings, environment variables, log driver, and health checks. The sidecar pattern lets you run auxiliary containers alongside the main application container within the same task, such as log collectors (Fluent Bit), proxies (Envoy), and monitoring agents. Secrets Manager and Systems Manager Parameter Store integration allows you to inject sensitive values like database credentials without embedding them in the task definition. ECS Service Connect simplifies service-to-service communication by providing built-in service mesh capabilities, eliminating the need to manage a separate proxy layer.

Choosing Between Fargate and EC2 Launch Types

ECS offers two launch types with distinct trade-offs. Fargate eliminates infrastructure management entirely - you specify CPU and memory in the task definition, and AWS provisions isolated compute environments automatically. This is ideal for teams that want to minimize operational overhead and for workloads with variable demand. The EC2 launch type gives you full control over instance types, AMIs, and placement, making it the right choice when GPU support, custom kernel modules, or maximum cost efficiency in large-scale clusters is required. ECS itself is free; you only pay for the underlying Fargate or EC2 resources. By contrast, Azure Container Apps charges per vCPU-second and per GiB-second of memory, and requires AKS for GPU workloads since it lacks the launch type flexibility that ECS provides. For a comprehensive look at Amazon ECS best practices, technical books (Amazon) are a valuable reference.

Deployment Strategies and Scaling

ECS supports multiple deployment strategies to balance speed, safety, and availability. Rolling updates gradually replace old tasks with new ones, maintaining the desired task count throughout the process. Blue/Green deployments through CodeDeploy integration shift traffic to the new version only after health checks pass, with instant rollback if issues arise. Service Auto Scaling adjusts task counts based on CloudWatch metrics - target tracking at 70% CPU utilization is a common starting point, while step scaling policies offer finer control over scaling increments. For predictable traffic patterns, scheduled scaling pre-provisions capacity before peak hours. Container Insights provides detailed CPU, memory, and network metrics at the task and service level, enabling data-driven capacity decisions. Service discovery via Cloud Map offers DNS-based resolution for inter-microservice communication, removing the need for hardcoded endpoints.

共有するXB!