AWS — ECS
What is ECS?
Managed container orchestration service for Docker containers.
Create cluster
aws ecs create-cluster --cluster-name my-cluster
Register task definition
{
"family": "my-task",
"containerDefinitions": [
{
"name": "my-container",
"image": "nginx:latest",
"cpu": 256,
"memory": 512,
"portMappings": [
{"containerPort": 80, "hostPort": 80}
]
}
]
}
aws ecs register-task-definition --cli-input-json file://task.json
Run task
aws ecs run-task \
--cluster my-cluster \
--task-definition my-task:1
Create service
aws ecs create-service \
--cluster my-cluster \
--service-name my-service \
--task-definition my-task:1 \
--desired-count 2 \
--launch-type FARGATE \
--network-configuration "awsvpcConfiguration={subnets=[subnet-xxx],securityGroups=[sg-xxx]}"
Fargate vs EC2
| Feature | Fargate | EC2 |
|---|---|---|
| Serverless | Yes | No |
| Instance mgmt | AWS | You |
| Pricing | Per task | Per instance |
| Flexibility | Limited | Full |
Scaling
aws ecs update-service \
--cluster my-cluster \
--service my-service \
--desired-count 4
Auto scaling
aws application-autoscaling register-scalable-target \
--service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount \
--resource-id service/my-cluster/my-service \
--min-capacity 2 \
--max-capacity 10
Best practices
- Use Fargate for simplicity
- Set up auto scaling
- Use task roles for permissions
- Monitor with CloudWatch
Mini Practice
- Create a cluster
- Deploy a task definition
- Create a service
- Set up auto scaling
Up Next
Continue with EKS - Kubernetes Service.
Related Topics
Frequently Asked Questions about ECS
What is ECS in AWS?
ECS is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn ECS?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn ECS.
Why is ECS important in AWS?
ECS is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.