DEV Community

Udoh Deborah
Udoh Deborah

Posted on

Day 48 : Amazon ECS

Amazon Elastic Container Service.

Definition:

ECS (Amazon Elastic Container Service)

Amazon ECS is a container orchestration service that helps you run Docker containers at scale without having to manually manage servers.

Key points:
• Fully managed by AWS → no need to install or operate container orchestration software.
• Supports Docker containers → you package your application into Docker containers, and ECS runs them.
• Launch types:
• EC2 Launch Type → containers run on EC2 instances that you manage.
• Fargate Launch Type → serverless option; AWS manages the infrastructure. You just define the container requirements (CPU, memory).
• Integrations: Works smoothly with other AWS services like:
• Elastic Load Balancer (ELB) : distributes traffic to containers.
• CloudWatch: monitoring and logging.
• IAM : access and security.
• VPC :networking.
• Use case: Run microservices, web apps, APIs, background jobs, etc.

In short ECS = AWS-native way to run containers with minimal management overhead.

EKS (Amazon Elastic Kubernetes Service)

Amazon EKS is a managed Kubernetes service.

Key points:
• Kubernetes-native → If your team is already using Kubernetes, EKS lets you migrate workloads to AWS without running your own Kubernetes control plane.
• Distributed control plane → EKS manages Kubernetes masters for you, while you manage worker nodes (EC2 or Fargate).
• Open-source ecosystem → You get all Kubernetes features: Helm charts, operators, CRDs, etc.
• Flexibility → You can run EKS across multi-cloud and on-premises with EKS Anywhere.
• Community-driven → Kubernetes has one of the largest open-source communities.

In short → EKS = Kubernetes on AWS (more flexibility, but more complexity).

ECS vs EKS (Side-by-Side)

Feature ECS EKS
Orchestration Engine Proprietary AWS service Kubernetes (open-source)
Complexity Easier to use More complex, requires Kubernetes knowledge
Flexibility Limited (only AWS ecosystem) High (multi-cloud, hybrid, custom Kubernetes configs)
Scaling Via AWS Auto Scaling & ECS Service Native Kubernetes Horizontal Pod Autoscaler (HPA)
Community AWS-driven Large global open-source community
Best For Beginners, AWS-only workloads Teams already using Kubernetes

Rule of thumb:
• Use ECS → if you want simplicity and AWS-only environment.
• Use EKS → if you want Kubernetes features, portability, and ecosystem support.

  • Containers & Orchestration (Background)

To better understand ECS/EKS, let’s define containers and orchestration:
• Containers → lightweight, portable packages of an application with everything it needs to run (code, runtime, dependencies).
• Orchestration → automation of deployment, scaling, networking, and management of containers.

Without orchestration → you’d have to manually run containers, monitor failures, restart them, and balance traffic.
With orchestration → ECS/EKS does all that for you automatically.

Task: Run Nginx on ECS (Fargate)

Step 1: Create a Docker Image for Nginx (Optional)

AWS ECS already supports official Nginx images from Docker Hub, so you can skip this step unless you want a custom image.

If custom

# Dockerfile
FROM nginx:latest
COPY index.html /usr/share/nginx/html

Enter fullscreen mode Exit fullscreen mode

Build & push to Amazon ECR (Elastic Container Registry):

aws ecr create-repository --repository-name my-nginx
docker build -t my-nginx .
docker tag my-nginx:latest <AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/my-nginx:latest
aws ecr get-login-password --region <REGION> | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com
docker push <AWS_ACCOUNT_ID>.dkr.ecr.<REGION>.amazonaws.com/my-nginx:latest

Enter fullscreen mode Exit fullscreen mode

Step 2: Create a Cluster

Go to AWS Console → ECS → Clusters → Create Cluster
• Choose Fargate.
• Name it: nginx-cluster.

Step 3: Define a Task Definition

A Task Definition tells ECS what container to run and how.
• Go to ECS → Task Definitions → Create New Task Definition.
• Choose Fargate.
• Set:
• Task Name: nginx-task.
• Task Role: ecsTaskExecutionRole.
• Container:
• Name: nginx-container.
• Image: nginx:latest (or your ECR image).
• Port Mappings: 80 → 80.

Save Task Definition.

Step 4: Run a Service

A Service ensures that your Task keeps running.
• Go to ECS → Cluster → nginx-cluster.
• Click Create Service.
• Launch Type: Fargate.
• Task Definition: nginx-task.
• Desired Tasks: 1.
• Networking: Choose VPC + public subnet + enable auto-assign public IP.

Step 5: Access Nginx
• After service is running → Go to Tasks tab → Copy the Public IP.
• Open browser → http:// → You should see Nginx welcome page 🎉.

Top comments (0)