
AWS Compute Series — Day 5: Amazon ECS
Understanding Container Orchestration
Series: AWS Compute Series (5 articles)
- …
- 5AWS Compute Series — Day 5: Amazon ECS This article
In our previous articles, we explored different ways to deploy applications on AWS.
We looked at virtual machines, serverless functions, managed application platforms, and simplified cloud hosting.
But what happens when an application is packaged into multiple containers?
Imagine a web application composed of:
- A frontend container.
- A backend API container.
- A background worker container.
How do we deploy these containers, keep them running, connect them, replace failed containers, and scale them when traffic increases?
Running containers is one thing.
Managing them reliably in production is another.
This is where Amazon Elastic Container Service (Amazon ECS) comes in.
1. What is Amazon ECS?
Amazon ECS is a fully managed container orchestration service that helps you deploy, manage, and scale containerized applications.
It coordinates the execution of containers across your chosen compute infrastructure.
Instead of manually starting and monitoring every container, you describe the desired state of your application.
ECS helps maintain that state.
For example, you can tell ECS:
"I want three running instances of my backend application."
ECS schedules the tasks, monitors their status, and can replace failed tasks to maintain the desired number.
Important: ECS is an orchestration service, not a container image registry or a container runtime that you manage directly.
It works with services such as:
- Amazon ECR to store container images.
- AWS Fargate or Amazon EC2 to provide compute capacity.
- Elastic Load Balancing to distribute incoming traffic.
- Amazon CloudWatch for logs and monitoring.
2. Understanding the main ECS building blocks
To understand ECS, you need to master five concepts.
A. Cluster
A cluster is a logical grouping of tasks and services.
It provides an organizational boundary for your containerized workloads and connects them to the infrastructure capacity on which they run.
Think of a cluster as the environment in which your application workloads are organized.
A cluster does not necessarily mean a collection of EC2 virtual machines. ECS can also run tasks using Fargate.
B. Task Definition
A task definition is a blueprint describing how your application containers should run.
It specifies important configuration such as:
- Container image.
- CPU and memory requirements.
- Port mappings.
- Environment variables.
- Storage and volume configuration.
- Logging configuration.
- IAM roles.
- Health checks.
For example, a task definition might specify:
- Image:
my-backend\:v1
- CPU: 0.5 vCPU
- Memory: 1 GB
- Container port: 8000
- Log destination: Amazon CloudWatch LogsA task definition is versioned through revisions.
When you change the configuration, ECS can use a new revision to launch tasks with the updated settings.
This is particularly important during application deployments.
C. Task
A task is a running instance of a task definition.
The task definition describes what should run.
The task represents an actual execution of that configuration.
A task can contain one or multiple containers that are scheduled together.
For example, you could run a backend container and a closely related logging sidecar within the same task.
D. Service
An ECS service manages the lifecycle of long-running tasks.
Suppose you configure a service with:
Desired task count = 3 ECS attempts to maintain three running tasks.
If one task fails or stops unexpectedly, the service scheduler can launch a replacement.
A service can also integrate with a load balancer and support automatic scaling.
This makes it particularly useful for web applications and microservices.
E. Container Image
ECS needs an image from which to create your containers.
You can use images stored in Amazon Elastic Container Registry (ECR), Docker Hub, or another supported registry.
For production deployments, image versioning matters.
Avoid relying on the mutable
latest tag as your only deployment reference.Use versioned tags or immutable image digests so you can identify exactly which image is running.
3. How does an ECS deployment work?
Let's consider a simplified Django backend application.
The deployment process looks like this:
Source Code → Docker Build → Container Image → Amazon ECR → ECS Task Definition → ECS Service → Running Task Step by step:
1. Developers write and test the application.
2. Docker builds the application image.
3. The image is pushed to Amazon ECR.
4. An ECS task definition references that image.
5. An ECS service uses the task definition.
6. ECS schedules the task on the selected compute infrastructure.
7. The container starts and runs the application.
8. A load balancer can route incoming requests to healthy tasks.
A CI/CD pipeline can automate much of this process.
For example, after a successful GitLab CI pipeline:
- Build the frontend and backend images.
- Push the images to ECR.
- Register updated ECS task definition revisions.
- Update the ECS services.
- Monitor deployment health.
One important lesson:
Pushing a new image to ECR does not automatically mean your running ECS service is using it.
The task definition and service deployment must be updated appropriately.
4. ECS compute options: Fargate, EC2, and Managed Instances
This is one of the most important concepts in ECS.
ECS manages container orchestration, but you must also choose where your containers run.
There are three major infrastructure options to understand.
A. Amazon ECS on AWS Fargate
Fargate is a serverless compute engine for containers.
You define the CPU and memory required by your tasks.
AWS manages the underlying server infrastructure.
You do not need to provision, patch, or maintain the EC2 instances hosting your containers.
Advantages:
- Reduced infrastructure management.
- Flexible task-level resource allocation.
- Automatic infrastructure provisioning.
- Useful for variable workloads.
- Pay for the resources requested by running tasks.
This is a good starting point when you want to focus on containers rather than managing servers.
B. Amazon ECS on EC2
With this option, your containers run on EC2 instances registered with your ECS cluster.
You manage the underlying infrastructure, including:
- Instance types.
- Operating systems.
- Capacity planning.
- Instance updates and patching.
- Infrastructure scaling.
Advantages:
- Greater control over compute infrastructure.
- More customization options.
- Ability to use specialized EC2 instance types.
- Potential cost optimization for predictable workloads.
However, you also inherit more operational responsibility.
C. Amazon ECS Managed Instances
ECS Managed Instances provide another option.
AWS manages the underlying EC2 instances, including provisioning, patching, and scaling, while you retain more infrastructure flexibility than with Fargate.
This option helps bridge the gap between fully serverless container execution and directly managing EC2 instances.
It is important to understand that this is not identical to Fargate: Managed Instances use EC2 capacity and include an additional management fee.
The central distinction:
Option | Who manages the underlying infrastructure?\ |
|---|---|
Fargate | AWS\ |
EC2 | You\ |
ECS Managed Instances | AWS manages the EC2 instances |
The best option depends on workload requirements, control, operational capacity, and cost.
5. How does ECS handle networking?
Containers need to communicate with other containers, databases, load balancers, and external clients.
ECS integrates with Amazon VPC to provide networking capabilities.
For Fargate tasks, the
awsvpc network mode is used.Each task receives its own Elastic Network Interface (ENI) and private IP address.
This allows you to associate security groups directly with tasks.
For example, imagine this architecture:
Internet → Application Load Balancer → Frontend Service → Backend Service → Database You can configure security groups to control which components are allowed to communicate.
A good security approach might be:
- Allow public HTTPS traffic to the load balancer.
- Allow frontend traffic only from the load balancer.
- Allow backend traffic only from authorized application components.
- Allow database connections only from the backend.
The objective is to avoid exposing every component directly to the internet.
Networking is not an optional detail in container orchestration.
It is part of the architecture.
6. How does ECS scale applications?
ECS supports scaling at different levels.
A. Task-level scaling
An ECS service can increase or decrease its desired task count.
For example:
- Normal traffic: 2 backend tasks.
- Increased traffic: 5 backend tasks.
- Reduced traffic: 2 backend tasks.
B. Service Auto Scaling
ECS integrates with Application Auto Scaling.
You can configure scaling policies based on metrics such as:
- Average CPU utilization.
- Average memory utilization.
- Application load balancer request count per target.
This allows the service to adjust the number of running tasks based on demand.
C. Infrastructure capacity scaling
When using EC2 infrastructure, you must also ensure that sufficient compute capacity is available to run the tasks.
Capacity providers can help coordinate task placement with infrastructure capacity.
With Fargate, AWS manages the underlying compute capacity.
Remember: Scaling the number of tasks and scaling the infrastructure underneath them are related, but they are not the same operation.
7. How are ECS applications deployed and updated?
Deployments are another important part of ECS.
Imagine your backend application is currently running version 1.
You build version 2 and push its image to ECR.
How do you replace the running application?
You update the task definition to reference the new image and deploy the new revision through the ECS service.
ECS supports deployment strategies, including rolling deployments.
During a rolling deployment, ECS gradually replaces existing tasks with new tasks while respecting the configured deployment parameters.
You should understand:
- Minimum healthy percentage.
- Maximum percentage.
- Health checks.
- Deployment circuit breaker.
- Automatic rollback configuration.
These settings influence how ECS replaces tasks and handles unsuccessful deployments.
A deployment is not successful simply because a container starts.
The application must also become healthy and serve requests correctly.
8. Monitoring and observability
A container can be running without the application actually working correctly.
This is why observability matters.
ECS integrates with Amazon CloudWatch for monitoring and logging.
You can monitor:
- CPU utilization.
- Memory utilization.
- Task state changes.
- Service events.
- Application logs.
- Container health.
For more advanced observability, you can integrate additional monitoring tools and telemetry solutions.
For example, Prometheus and Grafana can help monitor application and infrastructure metrics.
A useful operational principle:
Running does not necessarily mean healthy, and healthy does not necessarily mean useful.
You must monitor both infrastructure and application behavior.
9. Security considerations
Container orchestration does not automatically make an application secure.
Important security practices include:
- Use IAM roles with least privilege.
- Separate the task execution role from the task role.
- Store sensitive credentials in AWS Secrets Manager or Systems Manager Parameter Store.
- Use security groups to restrict network traffic.
- Scan container images for vulnerabilities.
- Avoid running containers with unnecessary privileges.
- Use trusted and regularly updated base images.
- Configure appropriate logging and monitoring.
- Keep task definitions and deployment configurations under version control.
Two IAM roles deserve special attention:
Task execution role: Used by the ECS agent or Fargate infrastructure to perform operations required to start the task, such as pulling images from ECR and sending logs to CloudWatch.
Task role: Provides AWS permissions to the application code running inside the container.
They serve different purposes and should not be confused.
10. Understanding ECS pricing
Amazon ECS does not have a separate orchestration charge for the standard EC2 and Fargate options.
However, the resources used by your application are billable.
With Fargate, pricing is based primarily on:
- Requested vCPU.
- Requested memory.
- Operating system and CPU architecture.
- Additional configured ephemeral storage.
With EC2, you pay for the infrastructure resources used to run your containers.
ECS Managed Instances also include a management fee in addition to the underlying EC2 charges.
Other possible costs include:
- Amazon ECR storage and image transfers.
- Application Load Balancer.
- CloudWatch logs and metrics.
- Public IPv4 addresses.
- Data transfer.
- EBS volumes when using EC2 infrastructure.
A critical lesson for cloud engineers:
A service being managed does not mean the architecture is free.
Before deploying, estimate the complete architecture and identify every billable resource.
11. ECS vs EC2 vs Lambda vs EKS
Let's put the services into perspective.
Service | Primary purpose |
|---|---|
Amazon EC2 | Virtual machine infrastructure |
AWS Lambda | Event-driven function execution |
Amazon ECS | Container orchestration |
Amazon EKS | Managed Kubernetes control plane and Kubernetes integration |
ECS is AWS-native container orchestration.
EKS provides managed Kubernetes.
Both can run containerized applications, but they expose different operational models and ecosystem choices.
ECS is often a simpler starting point when you want to run containers on AWS without adopting Kubernetes.
EKS becomes relevant when Kubernetes compatibility, its ecosystem, or Kubernetes-specific operational requirements matter.
We'll explore EKS in a future article.
12. The practical takeaway for a DevOps or Platform Engineer
Understanding ECS means understanding more than Docker commands.
You should be able to explain:
- What is the difference between an image and a container?
- What is a task definition?
- What is an ECS task?
- What is the role of an ECS service?
- What does a cluster represent?
- What is the difference between Fargate and EC2?
- How does ECS replace failed tasks?
- How are containers connected to a VPC?
- How does a CI/CD pipeline deploy a new task definition revision?
- How do you monitor application health?
These concepts are fundamental to designing and operating containerized applications in the cloud.
If you have worked with Docker Compose, ECS is a useful next step.
Docker Compose helps define and run multi-container applications.
ECS adds an orchestration layer for deploying, scheduling, maintaining, and scaling container workloads in AWS.
The shift is from running containers to operating containerized applications reliably.
---
Coming next: Day 6 — Amazon EKS | Understanding Kubernetes on AWS
We'll explore Kubernetes, the control plane, worker nodes, pods, deployments, services, and how EKS fits into the AWS container ecosystem.
Learn • Build • Share • Certify
Further reading — AWS official documentation:
Series: AWS Compute Series (5 articles)
- …
- 5AWS Compute Series — Day 5: Amazon ECS This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article