AWS ECS
Elastic Container Service
AWS's container orchestration service. Easily deploys, manages, and scales Docker containers.
Elastic Container Service
AWS's container orchestration service. Easily deploys, manages, and scales Docker containers.
AWS ECS (Elastic Container Service) is a fully managed container orchestration service provided by AWS. It lets you easily run, stop, and manage Docker containers on AWS infrastructure, and you can operate container-based applications without your own container management tools or Kubernetes.
It reached GA (General Availability) in 2015 and is the oldest container service on AWS. It supports two methods: EC2 Launch Type (managing EC2 instances directly) and Fargate Launch Type (serverless containers). With Fargate, you only define the containers, and AWS automatically manages the infrastructure without server provisioning, patching, or scaling.
The core concepts of ECS are Cluster (container execution environment), Service (long-running task management), Task Definition (container configuration blueprint), and Task (the actual running instance). It integrates automatically with ALB/NLB, making traffic distribution easy, and Service Auto Scaling enables automatic scaling based on CPU/memory.
In practice, ECS has a lower learning curve than Kubernetes and offers excellent native AWS integration, making it well suited for teams that want to adopt containers quickly in an AWS-centric infrastructure. You can manage image repositories by integrating with ECR (Elastic Container Registry), and easily implement Blue/Green deployments and Rolling deployments by integrating with CodePipeline/CodeDeploy.
{
"family": "my-app",
"networkMode": "awsvpc",
"requiresCompatibilities": ["FARGATE"],
"cpu": "512",
"memory": "1024",
"executionRoleArn": "arn:aws:iam::123456789012:role/ecsTaskExecutionRole",
"taskRoleArn": "arn:aws:iam::123456789012:role/ecsTaskRole",
"containerDefinitions": [
{
"name": "app",
"image": "123456789012.dkr.ecr.ap-northeast-2.amazonaws.com/my-app:latest",
"essential": true,
"portMappings": [
{
"containerPort": 8080,
"protocol": "tcp"
}
],
"environment": [
{
"name": "NODE_ENV",
"value": "production"
}
],
"secrets": [
{
"name": "DATABASE_URL",
"valueFrom": "arn:aws:secretsmanager:ap-northeast-2:123456789012:secret:db-url"
}
],
"logConfiguration": {
"logDriver": "awslogs",
"options": {
"awslogs-group": "/ecs/my-app",
"awslogs-region": "ap-northeast-2",
"awslogs-stream-prefix": "ecs"
}
},
"healthCheck": {
"command": ["CMD-SHELL", "curl -f http://localhost:8080/health || exit 1"],
"interval": 30,
"timeout": 5,
"retries": 3,
"startPeriod": 60
}
}
]
}
"If we go with ECS Fargate, we don't have to manage EC2 instances, and costs are calculated per task, so they're easy to predict. It integrates automatically with the ALB, and since ECR image pulls are authenticated with an IAM Role, you just change the image URL and deploy. Blue/Green deployment works right away if you integrate CodeDeploy."
"We operated 10 microservices on ECS Fargate. We managed secrets in the Task Definition through Secrets Manager integration, collected metrics with Container Insights, and set up Auto Scaling with a CPU threshold of 70%. For deployment, an ECR push in CodePipeline triggers the ECS service update, which is automatically rolled out as a rolling deployment."
"The ECS task keeps restarting, and the CloudWatch logs show OOMKilled. I raised the memory to 1GB in the Task Definition, but the actual container is using more. We need to increase the memory value and check whether the application has a memory leak. And let's also set the healthCheck startPeriod generously to secure enough initial startup time."
Take a mock interview on this topic → WIA SOOM AI Interview · Start for free
ECS requires two separate roles: the Task Execution Role (for AWS API calls — ECR pulls, CloudWatch logging) and the Task Role (for AWS API calls inside the application — S3, DynamoDB access). Confusing the two causes permission errors.
Fargate uses the awsvpc network mode. If placed in a Private Subnet, a NAT Gateway is required to pull images from ECR. Setting up VPC Endpoints (ECR, S3, CloudWatch Logs) makes this possible without a NAT Gateway and also reduces costs.
Enable deployment_circuit_breaker on the Service so that deployments automatically roll back on failure. Turn on Container Insights to collect metrics, and ensure high availability with at least 2 tasks. Using Fargate Spot can save up to 70% in costs, but interruptions are possible, so consider fault tolerance.