AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
📦 Amazon ECS (Elastic Container Service)
🧠🚢
45
Amazon ECS is a fully managed container orchestration service . It helps you run and
manage Docker containers on a cluster of EC2 instances or using serverless (Fargate).
24
● No need to install your own container orchestration software.
av
● Integrates with Elastic Load Balancing, IAM, CloudWatch, and more.
bh
● Two launch types: EC2 and Fargate.
📌 Exam Tip: ECS is AWS’s proprietary alternative to Kubernetes (which is EKS). Know when
to use ECS vs EKS.
ai
/v
🧩 What are ECS Tasks?
om
A Task is the basic unit of work in ECS 🛠️.
.c
● A task is launched from a Task Definition (like a recipe📄for containers).
ub
● A task can run one or more containers.
● You define CPU, memory, networking, and IAM roles in the task definition.
ith
📌 Exam Tip: Tasks run your containers. They're often asked about in context of Task
//g
Definitions and Service Auto Scaling.
⚙️ ECS - EC2 Launch Type (Features in short)
s:
tp
● You manage the EC2 instances yourself 🧑💻
.
ht
● You pay for the EC2 instances even if they’re underutilized.
● Best when you need deep control over the infrastructure (e.g., custom AMIs, logging
agents).
● Use Auto Scaling Groups to scale ECS capacity.
📌 Exam Tip: Choose EC2 launch type when you want OS-level control or have steady
workloads.
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
☁️ ECS - Fargate Launch Type (Features in short)
● Serverless container hosting 💨🧳 — no need to manage EC2 instances.
● You only pay for CPU and memory used by containers.
● Easily scalable and great for microservices.
45
📌 Exam Tip: Fargate = no server management. Used when you want simplicity and
cost-efficient scaling.
24
🔐 IAM Roles for ECS (In Short)
av
🧾
bh
1. Task Role : Assigned to the ECS task so containers can access AWS services (e.g.,
S3, DynamoDB).
ai
2. Execution Role 🚀: Used by ECS to pull container images from ECR and write logs
/v
to CloudWatch.
🖥️: Lets EC2 instances register to ECS
om
3. Container Instance Role (for EC2 launch type)
and talk to other AWS services.
.c
📌 Exam Tip: Understand the difference between Task Role vs Execution Role.
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
🚀 Create ECS Cluster (Fargate + EC2)
1. Go to ECS > Clusters > Create Cluster
2. Name your cluster: DemoCluster 🏷️
3. Select Capacity Providers:
✅ AWS Fargate (serverless)
45
○
○ ✅ Amazon EC2 -Create Auto Scaling Group
24
Infrastructure :-
av
bh
ai
/v
om
.c
ub
ith
//g
s:
tp
🌐
ht
4. Keep Network settings default
5. Provisioning:
○ Choose On-demand or Spot ⚡
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
6. EC2 Settings:
○ AMI: Amazon Linux 2 🐧
○ Instance type: t2.micro 💻
○ IAM role: Create one if needed 🔐
○ Capacity: Min 0, Max 2
45
7. Key Pair: Create one if you want SSH access 🔑
24
8. EBS Volume: Default 30 GB 💽
av
9. Click Create ✅
bh
ai
/v
om
🔍 Check ASG for ECS Cluster
.c
📊
ub
1. Go to EC2 Console → Auto Scaling Groups
2. Look for ASG named like ECS-Cluster-DemoCluster-...
3. Verify:
ith
✅
📈
○ Instance type
//g
🌐
○ Capacity (e.g., 0–2)
VPC/Subnet
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
45
✅
Go to ECS > Clusters > DemoCluster > Infrastructure tab to see attached Capacity
Providers like FARGATE and EC2 .
24
av
bh
💡 ai
Capacity Providers in ECS define where and how your tasks run — on Fargate, EC2, or
/v
Spot .
om
● FARGATE → Serverless, no EC2 to manage 🚀
● EC2 → Use your own EC2 instances 🖥️
💰
.c
● FARGATE_SPOT → Run on spare capacity, cheaper
🚀
ub
Change ASG Desired Capacity from 0 to 1
ith
🖥️
● Set desired capacity to 1 in your Auto Scaling Group.
● AWS launches a new EC2 instance.
//g
🤝
● The instance automatically registers itself to the ECS Cluster. Check in Container
Instances
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
45
24
av
bh
ai
/v
om
.c
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
🚀 Create a New Task Definition in ECS (Fargate) —
Example with nginxdemos/hello 🎯
This example will walk you through creating a simple ECS Task Definition using Fargate,
which runs a container from the image nginxdemos/hello. This is perfect for testing or
learning the ECS basics!
🧱 Step-by-Step Guide
45
1️⃣ Create a New Task Definition
24
● Go to Amazon ECS Console
av
✅
● Choose Task Definitions → Create new task definition —> Give Name
● Select FARGATE as the launch type ( serverless)
bh
2️⃣ Infrastructure Requirements
ai
● Operating system/Architecture: Linux/X86_64 (default)
/v
● Network mode: awsvpc (auto-selected for Fargate)
● Task Size:
om
○ CPU: 0.5 vCPU
○ Memory: 1 GB
.c
(You can change this as per your workload needs)
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
3️⃣ Task Roles
● Task Role: Leave blank if your container doesn't need to call AWS services.
● Task Execution Role:
○ Click Create new role (ECS will create a role with permissions to pull the image
and log to CloudWatch)
45
4️⃣ Add Container
24
● Click Add container
● Container name: hello-container (or any name you like)
av
Image URI:
bh
bash
ai
CopyEdit
nginxdemos/hello
/v
● 👉 This image is hosted on Docker Hub: https://hub.docker.com/r/nginxdemos/hello/
om
● Port mappings:
.c
○ Container port: 80
ub
○ Protocol: tcp
ith
//g
s:
tp
ht
✅ Leave all other settings as default
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
5️⃣ Review and Create
● Review your configuration
● Click Create
● You now have a task definition ready to be used in a service or for a one-time task run!
45
24
av
bh
ai
/v
om
.c
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
🚀 Launch ECS Task Definition as a Service (Fargate + ALB)
1️⃣ Go to ECS → Clusters → Select DemoCluster
Click Services → then Add Service
2️⃣ Service Details
● Launch type: Select Launch Type ( 🟦 FARGATE)
45
● Deployment type: Replica
● Keep other values as default
24
3️⃣ Environment Configuration
av
● Cluster: DemoCluster
● Launch type: FARGATE
bh
● Platform version: LATEST
ai
/v
om
.c
ub
ith
//g
4️⃣ Networking
s:
● VPC: Select your VPC
● Subnets: Select multiple subnets (high availability across AZs)
tp
● Security group:
ht
○ Select Create a new security group
○ Name: nginxdemos-hello
○ Description: SG For ECS Nginx Demo
○ Inbound rule:
■ Type: HTTP
■ Port: 80
■ Source: Anywhere (0.0.0.0/0 and ::/0)
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
45
24
av
bh
5️⃣ Load Balancing
✅
●
ai
Enable "Use load balancing"
/v
● Load balancer type: Application Load Balancer
● Container to load balance:
om
○ Choose nginxdemos-Hello 80:80
● Create a new load balancer:
○ Name: DemoALBforECS
.c
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
6️⃣ Listener & Target Group
● Create new listener:
○ Port: 80
○ Protocol: HTTP
● Create new target group:
45
○ Name: tg-nginxdemos-hello
○ Protocol: HTTP
24
○ Deregistration delay: 300
○ Health check protocol: HTTP
○ Health check path: /
av
bh
ai
/v
om
.c
ub
ith
//g
s:
tp
Keep Rest Of The Configuration Default For The Same.
✅ Final Step: Click Create Service
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
45
Click On The Service
24
av
bh
ai
/v
om
.c
ub
You Can See The Service is Linked To Target Group.
ith
//g
s:
tp
ht
You can see the Target Group is linked to Application Load Balancer.
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
✅ Verifying Load Balancer and Target Group for nginx
Container
🚀
Once your ECS container (running nginx) is up and running, follow the steps below to verify
everything is working perfectly!
🔹 Step 1: Check Registered Targets in the Target Group
45
1. Go to the EC2 Console.
2. In the left menu, click on Target Groups under Load Balancing.
24
3. Select your target group (used by the ALB).
4. Click on the Targets tab.
You will see a registered IP address (e.g., 172.31.42.191).
av
5.
👉 This IP address is the private IP of your container running nginx.
✅ Make sure the Health status shows "Healthy" 💚 — this means the Load Balancer can
bh
reach your container.
ai
/v
om
.c
ub
ith
//g
🔹 Step 2: Test the Application Using the Load Balancer
s:
tp
1. Go to the EC2 Console → Load Balancers.
2. Select your ALB (Application Load Balancer).
ht
3. Copy the DNS name of the ALB (e.g.,
demoalbforecs-xxxxxxxx.ap-south-1.elb.amazonaws.com).
4. Paste it in your web browser and hit Enter. 🌐
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
5. You should see the nginx welcome page with some server details like:
● Server address
● Server name
● Date and URI
45
24
av
bh
ai
/v
om
🔍 ECS Task & Logs Verification
.c
Check Task Details
ub
1. Go to ECS > Clusters > Your Cluster (e.g., DemoCluster) > Services > Your
ith
Service.
//g
2. Click on the Tasks tab.
3. Click on the running Task ID.
s:
4. Under the Configuration tab, you can see:
tp
ht
○ Task details (e.g., Task ARN, Status, ENI, Public IP, Subnet)
○ Platform version, Memory/CPU allocation, Launch type (FARGATE)
○ ✅ Confirm task is in Running state.
.
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
45
24
av
📄 View Container Logs
bh
1. Inside the task, switch to the Logs tab.
2. You will see log entries (like health check calls from ELB).
ai
/v
💡
○ Helps verify container responses (e.g., HTTP 200 from Nginx).
○ Useful for debugging or checking traffic.
om
.c
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
🛠️ Check ECS Service Events
1. Go to the Service again in your ECS Cluster.
2. Click the Events tab.
3. You'll see recent activity such as:
○ Task launched and registered to target group
○ Deployment completed
○ Service reached a steady state.
45
24
av
bh
ai
/v
om
.c
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
🔄 Scaling Tasks in ECS (Fargate)
🚀 Current State
You currently have 1 running task in your ECS Service
🔧 Step-by-Step to Scale Tasks
45
1. Go to ECS > Clusters > Your Cluster > Services.
2. Select your service (e.g., nginxdemos-Hello-service-Demo1).
24
➡️
3. Click on Update.
4. In the Desired Tasks field, change the value from 1 3.
5. Click Update to save.
av
✅ This tells ECS to run 3 copies (replicas) of your task.
bh
ai
/v
om
.c
ub
ith
//g
⚙️ What Happens Behind the Scenes?
s:
● Fargate provisions 2 more containers (total: 3) to meet the new desired count.
tp
● Each container runs the same task definition (image: nginxdemos/hello) but on
ht
separate ENIs (Elastic Network Interfaces) inside your subnet.
● These are managed by ECS and Fargate, meaning:
○ No need to manage EC2 instances
○ Fargate handles task placement, network setup, and IP assignment automatically
● All tasks get registered to the Target Group linked with your ALB (Application Load
Balancer).
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
🌐 Web Page Behavior After Scaling
1. Open the DNS of your ALB in a browser.
🎯
2. Refresh the page several times.
3. You’ll notice:
○ The IP address shown on the Nginx demo page keeps changing.
○ Why? Because the ALB is load balancing the traffic across all 3 ECS
containers.
45
○ This verifies that your service is horizontally scalable and traffic is being
handled efficiently.
24
av
bh
ai
/v
om
.c
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/
AWS ECS Hands-On & Notes By - Vaibhav Chaudhari
45
24
av
bh
ai
/v
om
.c
ub
ith
//g
s:
tp
ht
https://www.linkedin.com/in/vaibhav-chaudhari-14016b22a/