Elastic Container Service¶
ECS is AWS Docker Service. You can launch and modify containers as tasks in multiple ways depending on your application and scale.
Features¶
- support NLB, ALB
- support block storage – EFS
- use case → persistent multi-AZ shared storage for your containers.
- S3 can't be mounted in EC task.
Launch Types¶
EC2 Based¶
- Need to have a running EC2 as the host for your containers
- you must provision & maintain the infrastructure.
- You are billed for depending on the EC2
- The EC2 Instance must be running the ECS agent
Fargate Based / ECS Cluster¶
- No need to provision-Serverless
- Need tasks definitions
- Billed for CPU and memory used
- by default 20gb of free block storage
Roles¶
Instance Profile¶
Task Role¶
- Defines Permissions for the code running in the container (access to other services)
- each task can have a specific role
ECS Fargate Autoscaling¶
- Scale on CPU, Mem or ALB traffic per target
- ALB Request count per target - metric coming from ALB
- Scaling Fargate is easier
- Combine ECS cluster capacity prover paired with Auto Scaling group
Modes¶
- Target tracking
- Scale based on target value for specific CloudWatch metric
- Step calling
- Scale based on specific CloudWatch Alarm
- Scheduled scaling
- Scale based on specific date/time (predictable changes)
EC2 Autoscaling¶
- Horizontal scaling.
- Add more EC2 instances.
- Auto Scaling Group scaling.
- Scale your ASG based on CPU utilization.
- Add EC2 instances over time.
- EC2 Cluster capacity provider.
- Used to auto provision and scale the infra for your ECS tasks.
- Capacity provider paired with an auto-scaling group
- add EC2 instances when you are missing capacity (CPU, RAM)
Advanced Use Cases¶
- Use EventBride or docs/messaging/SQS to launch container, process tasks and shut down container afterward e.g: