Labs ICT
Pro Login

ECS Introduction

What is ECS?

ECS stands for Elastic Container Service. It's AWS's container orchestration platform, designed to run Docker containers at scale. Instead of managing individual servers, you define your containers and let ECS figure out where to run them.

Think of ECS as a traffic controller for containers. You tell it what containers you have and how many of each, and it schedules them across your infrastructure, monitors their health, and restarts them if they crash.

ECS vs EC2 vs Lambda

EC2 gives you a full virtual machine — you manage everything from the operating system up. Lambda runs individual functions without any server management. ECS sits in the middle — you manage your containers, but AWS manages the underlying infrastructure.

Containers are lighter than VMs but more flexible than functions. They package your code with all its dependencies, so "it works on my machine" actually means it works everywhere. ECS is perfect for applications that need more control than Lambda but less overhead than EC2.

ECS Launch Types

EC2 launch type gives you more control over the underlying instances. You choose the instance types, manage scaling, and are responsible for patching. It's like renting a building — you're in charge of maintenance.

Fargate launch type is serverless containers. AWS manages the instances entirely — you just define your containers and their resources. It's like staying at a hotel — everything is taken care of. Fargate is simpler but slightly more expensive per unit of compute.

Tasks and Services

A task is a running instance of your container definition. It's like pressing "play" on your application. A service ensures that a specified number of tasks are running at all times. If a task dies, the service automatically replaces it.

Services also integrate with load balancers, so incoming traffic is distributed across your tasks. It's the standard way to run production workloads on ECS — define a service, attach a load balancer, and let ECS handle the rest.

Getting Started with ECS

Start by creating a task definition — a JSON or YAML file that describes your container(s), their image, CPU/memory requirements, and port mappings. Then create a cluster and run your service.

aws ecs register-task-definition --cli-input-json file://task-definition.json
aws ecs create-service --cluster my-cluster --service-name my-service \
  --task-definition my-task --desired-count 2

This registers your task definition and creates a service with 2 running tasks. From here, you can scale up or down, deploy new versions, and monitor your containers.