Amazon ECS with EC2 Launch
Type. This
is where twtech runs its Docker containers on Amazon EC2 instances that twtech
manages itself.
The concept Amazon:
ECS - EC2 Launch Type
Amazon ECS (Elastic
Container Service) using the EC2 launch type. This means twtech can
provision and manage a cluster of EC2 instances that act as container
hosts.
ECS schedules and runs twtech
containers on these EC2 instances.
Architecture Overview
# sql
+---------------------------+
| Amazon ECS Cluster |
| +--------------------+ |
| EC2 Instance (x) |
| - ECS Agent |
| - Docker Engine |
| - Running Tasks |
| +--------------------+ |
| ... more nodes |
+---------------------------+
▲
|
▼
+----------------------------+
| ECS Scheduler |
| - Places tasks on EC2s |
+----------------------------+
▲
|
▼
+----------------------------+
|
Task Definitions |
|
- Container Specs |
|
- CPU/Memory limits |
|
- Port mappings |
+----------------------------+
AWS Useful link for Documentaion. https://docs.aws.amazon.com/AmazonECS/latest/developerguide/launch-type-ec2.html
Key Components
Component |
Description |
Cluster. |
Group of EC2 instances that ECS
manages. |
Task Definition. |
Blueprint for running containers
(image, CPU, memory, ports). |
Task. |
Running instance of a Task
Definition. |
Service. |
Ensures a specified number of
tasks are always running. |
ECS Agent. |
Installed on EC2 instances,
communicates with ECS. |
EC2 Instances. |
Container hosts (must use
ECS-optimized AMI or compatible OS). |
✅
Pros(benefits) of EC2 Launch Type
- Full control over EC2 instances (OS, networking, IAM,
monitoring).
- Can run daemon services or tools like
Prometheus, Fluentd, custom agents.
- More cost control with EC2 Reserved or Spot Instances.
- Easier integration with EBS volumes or custom networking.
❌
Cons(limitations)
- twtech must manage EC2 lifecycle (patching,
autoscaling, etc.).
- Less "serverless" than Fargate – more
overhead.
- Need to manage scaling of both instances and tasks.
Steps to Use ECS with EC2 Launch Type
- Create ECS Cluster
- With EC2 capacity (twtech can use ECS optimized AMIs)
- Set IAM roles, networking (VPC, Subnets, Security
Groups)
- Register Task Definition
- Define container image, ports, CPU/memory, volumes,
etc.
- Launch Service or Task
- Select EC2 launch type
- Specify how many tasks to run
- Auto Scaling (Optional)
- Use EC2 Auto Scaling groups
- Also possible to scale ECS tasks independently
Sample ECS EC2 Task Definition (JSON)
# json
{
"family": "twtech-ec2-app",
"containerDefinitions": [
{
"name": "twtechwebapp",
"image": "12345xxxxx.dkr.ecr.us-east-2.amazonaws.com/twtech-web-app:latest",
"memory":
512,
"cpu": 256,
"portMappings": [
{
"containerPort": 80,
"hostPort": 80
}
],
"essential": true
}
]
}
When twtech uses ECS with
EC2 Launch Type
Use Case |
Why ECS-EC2 is Suitable |
Custom monitoring/logging agents. |
Full access to the OS |
Use of specialized EC2 types (e.g.
GPU). |
Supports all EC2 types |
Long-running apps needing
persistence. |
Can mount EBS volumes |
Existing EC2 infra in place. |
Easy integration |
No comments:
Post a Comment