1. Scalability
Scalability means an application can handle increased load by adapting resources.
Types of Scalability
-
Vertical Scalability (Scale Up / Down):
- Increase instance size (more CPU, RAM, etc.).
- Example: Upgrading an EC2 instance from
t2.micro
โt2.large
. - Common for non-distributed systems like databases (RDS, ElastiCache).
- Limited by hardware capacity.
-
Horizontal Scalability (Scale Out / In):
- Add more instances to share the load.
- Example: Add more EC2 instances behind a Load Balancer.
- Common for distributed systems and web applications.
- In AWS: use Auto Scaling Groups.
2. High Availability (HA)
High availability means keeping the system operational even if one part fails.
- Achieved by running applications in multiple Availability Zones (AZs).
- Ensures resilience to data center or zone failure.
-
Example:
- EC2 Auto Scaling Group across 2+ AZs.
- RDS Multi-AZ (primary + standby replica).
-
Can be:
- Active-Passive: standby server takes over on failure.
- Active-Active: all instances handle traffic simultaneously.
3. Scalability vs. High Availability
Concept | Purpose | AWS Example |
---|---|---|
Scalability | Handle increased load | Auto Scaling (scale in/out) |
High Availability | Survive component failure | Multi-AZ Deployment |
4. Call Center Analogy
Concept | Example |
---|---|
Vertical scaling | One operator becomes faster (junior โ senior) |
Horizontal scaling | Hire more operators |
High availability | Operators distributed in multiple cities |
๐งญ What Is Load Balancing?
Definition:
Load balancing is the process of distributing incoming network traffic across multiple backend servers (EC2 instances) to ensure no single instance is overloaded.
In AWS, this is handled by Elastic Load Balancing (ELB) โ a fully managed service that automatically distributes traffic across targets such as EC2 instances, containers, IP addresses, and Lambda functions.
โ๏ธ How It Works
- Users connect to a single endpoint โ the load balancerโs DNS name.
- The load balancer forwards each request to one of several healthy backend instances.
- Traffic is distributed based on a routing algorithm (round-robin, least connections, etc.).
- Health checks continuously monitor backend instances to ensure only healthy ones receive traffic.
๐งฉ Why Use a Load Balancer
Benefit | Description |
---|---|
Single Access Point | Users access your app through one endpoint (DNS). |
Fault Tolerance | Automatically removes unhealthy instances. |
Scalability | Easily add or remove instances without downtime. |
SSL Termination | Manage HTTPS certificates at the load balancer level. |
Sticky Sessions (Cookies) | Keep users on the same instance if needed. |
Multi-AZ High Availability | Distribute traffic across Availability Zones. |
Security Segregation | Public-facing LB with private backend instances. |
๐ฉบ Health Checks
Health checks ensure traffic goes only to healthy targets.
Example configuration:
Protocol: HTTP
Port: 4567
Path: /health
If the endpoint returns an HTTP 200 OK, the instance is healthy.
If not, itโs marked unhealthy, and ELB stops routing traffic to it.
๐งฑ Types of Elastic Load Balancers
Type | Year | Protocols Supported | Layer | Use Case |
---|---|---|---|---|
Classic Load Balancer (CLB) | 2009 | HTTP, HTTPS, TCP, SSL | L4 + L7 | Legacy apps (deprecated) |
Application Load Balancer (ALB) | 2016 | HTTP, HTTPS, WebSocket | L7 | Modern web apps, microservices |
Network Load Balancer (NLB) | 2017 | TCP, TLS, UDP | L4 | High performance, low latency |
Gateway Load Balancer (GWLB) | 2020 | IP | L3 | Firewalls, security appliances |
โ Use ALB or NLB for most modern AWS applications.
๐ Security Groups Setup
1. Load Balancer Security Group
Inbound:
Port: 80, 443
Source: 0.0.0.0/0 (public access)
2. EC2 Instance Security Group
Inbound:
Port: 80
Source: Load Balancer Security Group (not an IP range)
This ensures only the load balancer can reach the backend instances.
๐ Integrations
Load balancers work seamlessly with:
- EC2 Auto Scaling Groups
- ECS / EKS containers
- AWS Certificate Manager (ACM)
- CloudWatch (monitoring)
- Route 53 (DNS)
- AWS WAF (security)
- Global Accelerator (performance)
๐ง Quick Recap
- Load balancers distribute traffic โ scalability
- Run across multiple AZs โ high availability
- Health checks + security groups โ resilience and safety
- Choose ALB or NLB depending on your app layer (HTTP vs TCP/UDP).
๐ฏ Application Load Balancer (ALB)
Layer 7 Load Balancer (HTTP/HTTPS)
โ Operates at the Application Layer (OSI Layer 7).
โ Understands HTTP headers, URLs, and cookies, enabling smart routing decisions.
๐ Key Features
Feature | Description |
---|---|
Layer 7 (HTTP/HTTPS) | Routes based on HTTP methods, headers, hostnames, paths, query strings. |
Multiple Applications, One ALB | One ALB can handle multiple apps or microservices (e.g., /user , /search ). |
Target Groups | Logical grouping of backend targets (EC2, ECS, Lambda, or IPs). |
Advanced Routing | - Path-based routing (/user , /search ) - Host-based routing ( api.example.com , admin.example.com ) - Query string or header-based routing. |
Redirects | Redirect HTTP โ HTTPS automatically. |
Protocol Support | HTTP/1.1, HTTP/2, WebSockets. |
Port Mapping (ECS) | Dynamically route to container ports (used with ECS). |
Fixed DNS Name | AWS assigns a static hostname for each ALB. |
Health Checks | Done per target group. |
๐งฉ Target Groups
A Target Group defines where the load balancer sends traffic.
Targets can be:
- EC2 Instances (managed manually or via Auto Scaling)
- ECS Tasks (containers)
- Lambda Functions
- Private IP Addresses (for hybrid or on-premises servers)
๐ก Health checks are configured per target group.
If targets fail health checks, ALB automatically stops sending them traffic.
๐ง Routing Example (Microservices)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Application Load Balancerโ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ
โ โ
/user โ โ /search
(Target Group 1) (Target Group 2)
EC2: User Service EC2: Search Service
-
/user
โ routed to Target Group 1 -
/search
โ routed to Target Group 2 - Both microservices share the same ALB endpoint
๐ง Routing by Query or Headers
Example rule:
If query string = Platform=Mobile โ Target Group 1
If query string = Platform=Desktop โ Target Group 2
This allows smart routing based on request parameters or headers.
๐งพ X-Forwarded Headers
When traffic passes through an ALB,
the backend does not see the original client IP directly.
AWS adds extra HTTP headers:
Header | Description |
---|---|
X-Forwarded-For |
Original client IP address |
X-Forwarded-Port |
Port used by client |
X-Forwarded-Proto |
Protocol (HTTP or HTTPS) |
Backend servers use these headers to log or identify the true client source.
๐ Security Overview
- ALB is public-facing (port 80/443).
- Backend EC2 instances allow only traffic from the ALBโs security group.
- This ensures end users canโt directly access your backend servers.
๐ง ALB vs. Classic Load Balancer (CLB)
Feature | Classic LB | Application LB |
---|---|---|
Layer | 4 & 7 | 7 only |
Routing | Basic | Path/Host/Header-based |
Multi-App Support | โ | โ |
WebSockets/HTTP/2 | โ | โ |
Container Support | โ | โ |
Cost Efficiency | Multiple LBs | One ALB for many apps |
๐งฎ Use Cases
โ
Microservices architecture
โ
Container workloads (ECS / EKS)
โ
Web applications requiring intelligent routing
โ
Hybrid apps (some on AWS, some on-premises)
โ
HTTPS redirection and centralized SSL management
โ๏ธ Lab: Launching an Application Load Balancer
Objective
Create two EC2 instances serving simple web pages and distribute traffic between them using an Application Load Balancer (ALB).
๐ช Step 1: Launch Two EC2 Instances
Go to EC2 โ Launch Instances
Name:
- Instance 1 โ
My First Instance
- Instance 2 โ
My Second Instance
AMI: Ubuntu
Instance Type:
t2.micro
(Free-tier)Key Pair: Proceed without key pair (weโll use EC2 Instance Connect)
Network Settings:
- Select existing security group
launch-wizard-1
-
Ensure inbound rules allow:
-
HTTP
(port 80) from anywhere -
SSH
(port 22) from your IP (optional)
-
- User Data Script: Paste the following script to auto-start a simple web server:
#!/bin/bash
apt update -y
apt install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello World from $(hostname -f)</h1>" > /var/www/html/index.html
-
Launch 2 instances and wait for both to reach
running
andStatus check: 2/2 passed
.
โ
Test:
Copy each instanceโs IPv4 public address and open it in a browser โ
you should see:
Hello World from ip-xxx-xxx-xxx-xxx.ec2.internal
๐ Step 2: Create an Application Load Balancer
- Go to EC2 โ Load Balancers โ Create Load Balancer
- Choose Application Load Balancer (ALB).
-
Name:
DemoALB
- Scheme: Internet-facing Address Type: IPv4
- Network Mapping:
- Select your VPC.
-
Enable all available Availability Zones.
- Security Group:
Create new one named
demo-sg-load-balancer
-
Allow Inbound:
- Type:
HTTP
- Port:
80
- Source:
0.0.0.0/0
- Type:
-
Outbound: default (allow all)
- Listeners and Routing:
Protocol:
HTTP
Port:
80
Create a new Target Group named
demo-tg-alb
๐ฏ Step 3: Create Target Group
- Target Type: Instances
- Protocol: HTTP
- Port: 80
-
Health Check Path:
/
(default OK) - Click Next โ Select both EC2 instances โ Include as pending โ Create target group
โ Your target group now includes both instances.
๐ Step 4: Attach Target Group to ALB
- In ALB creation wizard โ choose target group
demo-tg-alb
. - Review and click Create Load Balancer.
- Wait for ALB State: active.
๐ Step 5: Test the Load Balancer
- Copy the DNS name of your ALB (e.g.,
DemoALB-123456789.us-east-1.elb.amazonaws.com
). - Paste it into a browser.
You should see:
Hello World from ip-xx-xx-xx-xx.ec2.internal
๐ Refresh repeatedly:
Each refresh alternates between your two EC2 instances โ proof of load balancing!
๐ฉบ Step 6: Verify Health Checks
- Go to Target Groups โ demo-tg-alb โ Targets tab You should see:
i-xxxxx healthy
i-yyyyy healthy
- Stop one instance โ Wait ~30 seconds โ Refresh the target group page. The stopped instance becomes:
i-xxxxx unused (unhealthy)
The ALB automatically stops sending traffic to it.
- Restart the instance โ Wait for health status to become healthy again โ both instances resume receiving traffic.
โ Result
- One ALB endpoint distributing traffic evenly across two EC2 instances.
- Automatic detection of unhealthy instances.
- Seamless recovery once instances come back online.
๐ก Key Concepts Learned
Concept | Meaning |
---|---|
Target Group | Logical grouping of backend instances |
Health Check | Regular status probe (HTTP 200 OK ) to detect healthy targets |
Listener | Defines protocol/port and routing rules (e.g., HTTP:80 โ Target Group) |
DNS Name | Single entry point for users |
Security Model | ALB accepts public traffic; EC2 only from ALB SG |
โ๏ธ Advanced Concepts โ Application Load Balancer (ALB)
๐งฑ 1. Network Security Enhancement
๐งฉ Current Setup
-
Load Balancer SG:
demo-sg-load-balancer
โ allows inboundHTTP (80)
from anywhere. -
EC2 Instance SG:
launch-wizard-1
โ currently allows inboundHTTP (80)
from anywhere too.
This means users can bypass the ALB and directly access EC2 instances โ not ideal for production.
๐ Goal
โ
Allow only the load balancer to access EC2 instances.
โ Block direct public access to backend servers.
๐ช Steps to Tighten Security
- Go to EC2 โ Security Groups โ launch-wizard-1
- Click Edit inbound rules
- Delete the rule that allows:
Type: HTTP
Source: 0.0.0.0/0
- Add a new rule:
Type: HTTP
Source: demo-sg-load-balancer
(Select the security group of your ALB)
- Click Save rules
๐ Result
- Accessing EC2 instance directly via public IP โ โ Connection timed out
- Accessing via Load Balancer DNS โ โ Works perfectly!
This ensures traffic must pass through the ALB, achieving layered security.
๐ง 2. Listener Rules in ALB
Listeners define how incoming requests are routed.
Each listener listens on a port (e.g., 80/443) and processes rules top-to-bottom by priority.
๐งฉ Default Rule
โFor every request โ forward to target group
demo-tg-alb
.โ
Now weโll add custom rules to handle specific request paths or headers.
๐ช Steps to Add a Custom Rule
- Go to your ALB โ Listeners โ View/Edit Rules
- Add a New Rule
Name:
DemoRule
- Add Condition:
- Type:
Path
-
Value:
/error
- Action:
Choose Fixed Response
Status Code:
404
Content Type:
text/plain
-
Response Body:
Not found โ custom error
-
Set Priority:
5
(lower numbers = higher priority) - Save changes
-
Set Priority:
Now your rules look like:
Priority | Condition | Action |
---|---|---|
5 | Path = /error
|
Fixed Response (404) |
Default | All requests | Forward to demo-tg-alb
|
โ Test Your Rule
- Copy the ALB DNS name, e.g.:
http://DemoALB-123456789.us-east-1.elb.amazonaws.com
- Visit:
-
/
โ returns Hello World (from EC2 target group) -
/error
โ returns Not found โ custom error
๐ก The /error
path matched your new listener rule, so ALB responded directly with 404 instead of forwarding the request to instances.
๐งฉ 3. Rule Priority System
- ALB processes listener rules in order of priority (lowest = highest precedence).
- Example:
| Priority | Rule |
| -------- | ----------------------------- |
| 1 | /admin
โ Admin Target Group |
| 5 | /error
โ Fixed Response |
| Default | โ Main Target Group |
If multiple rules match, the rule with the lowest priority number wins.
๐ก Key Takeaways
Concept | Description |
---|---|
SG to SG reference | Restricts EC2 access to only the ALB |
Listener Rules | Define conditional routing for requests |
Fixed Response | Send custom responses without touching backend |
Priorities | Determine which rule executes first |
Path/Host/Header conditions | Enable advanced routing for microservices |
๐ Summary
- Secured backend instances (no direct internet access).
- Implemented custom ALB listener rules (path-based routing).
- Learned rule priority and conditional logic.
- Demonstrated fixed response (useful for error pages or maintenance).
โ๏ธ Network Load Balancer (NLB)
Layer 4 Load Balancer โ handles TCP and UDP traffic.
โ
Designed for ultra-high performance and low latency.
๐ง 1. Core Concepts
Feature | Description |
---|---|
Layer | Layer 4 โ Transport layer (TCP/UDP). Works below HTTP layer. |
Protocols Supported | TCP, UDP, TLS |
Performance | Millions of requests per second with microsecond latency. |
Static IPs | One static IP per Availability Zone (can assign Elastic IPs). |
High Availability | Multi-AZ support with failover. |
Health Checks | Supports TCP, HTTP, or HTTPS-based health checks. |
๐งฉ 2. When to Use NLB
Scenario | Why NLB? |
---|---|
High performance needed | Can handle millions of requests/sec. |
Static IP requirement | Use Elastic IPs for predictable endpoints. |
Non-HTTP traffic | Supports raw TCP/UDP connections (e.g., SMTP, RDP, DNS, gaming servers). |
Hybrid network setup | Can target on-prem servers via private IPs. |
Load balance HTTP apps with fixed IPs | Use NLB in front of ALB (NLB โ ALB). |
๐ก Exam Tip:
If the question mentions:
- โStatic IPs requiredโ
- โExtreme performanceโ
- โTCP or UDP trafficโ โ Answer: Network Load Balancer
๐๏ธ 3. Architecture Overview
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Network Load Balancer โ
โโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโ
โ โ
Target Group A Target Group B
(EC2 Instances) (Private IPs / On-Prem)
- Frontend listener: TCP or UDP port (e.g., 80, 443, 25)
- Backend targets: EC2 instances or private IP addresses
- Health checks: TCP/HTTP/HTTPS
- One static IP per AZ (Elastic IP optional)
๐ 4. Target Groups
Types of targets NLB can route to:
- EC2 Instances (same VPC)
- Private IPs (cross-network or on-prem)
- Other Load Balancers (e.g., ALB for HTTP logic)
๐ก Combo Pattern:
NLB (for static IPs) โ ALB (for routing rules).
This combines Layer 4 and Layer 7 benefits.
๐ฉบ 5. Health Checks
NLB Target Groups support 3 protocols for health checks:
Protocol | Use Case |
---|---|
TCP | Simple connectivity check (fast, low overhead). |
HTTP | Checks for valid HTTP 200 OK response. |
HTTPS | Secure health checks for encrypted endpoints. |
If a target fails its health check, NLB stops sending traffic until itโs healthy again.
๐ 6. Key Differences: ALB vs NLB
Feature | Application Load Balancer (ALB) | Network Load Balancer (NLB) |
---|---|---|
Layer | Layer 7 (HTTP/HTTPS) | Layer 4 (TCP/UDP/TLS) |
Protocol Awareness | Understands URLs, headers | Works with raw packets |
Static IPs | โ No | โ Yes |
Performance | High | Extremely high |
Use Case | Web apps, microservices | Gaming, databases, IoT, legacy TCP apps |
Health Checks | HTTP/HTTPS only | TCP/HTTP/HTTPS |
Integration | ECS, Lambda | Hybrid network, ALB chaining |
๐งพ Example Exam Question
โYour company must expose a TCP-based financial application that requires static IPs for firewall whitelisting and must handle millions of requests per second.โ
โ Answer: Network Load Balancer (NLB)
๐ง 7. Summary
- Layer 4 load balancer for TCP/UDP traffic.
- Supports static IPs (Elastic IPs per AZ).
- High performance + low latency.
- Can sit in front of ALB for combined benefits.
- Health checks: TCP, HTTP, HTTPS.
โ๏ธ Hands-On: Creating a Network Load Balancer (NLB)
๐ฏ Objective
Create a Network Load Balancer (Layer 4) to distribute TCP traffic between two EC2 instances and understand NLB-specific setup, routing, and security.
๐ช Step 1: Create the Network Load Balancer
- Go to EC2 โ Load Balancers โ Create Load Balancer
- Select Network Load Balancer
-
Name:
DemoNLB
- Scheme: Internet-facing Address type: IPv4
- Network Mapping:
- Select your VPC
- Enable all Availability Zones (AZs)
- Each AZ will automatically get one static IPv4 address โ You can replace these with Elastic IPs for fixed public IPs.
๐ก Tip: Each AZ = one static IP โ excellent for firewall whitelisting or static endpoint access.
๐งฑ Step 2: Create a Security Group for the NLB
- Click Create security group
-
Name:
demo-sg-nlb
-
Description: Allow HTTP into NLB
- Add Inbound Rule:
Type: HTTP
Port: 80
Source: 0.0.0.0/0
- Keep default outbound rule (allow all).
- Save and attach
demo-sg-nlb
to the load balancer.
โ Purpose: Controls inbound traffic into the NLB (acts as a front gate).
๐งฉ Step 3: Configure Listener & Target Group
- Under Listeners and Routing:
- Protocol:
TCP
-
Port:
80
- Create Target Group:
Name:
demo-tg-nlb
Target type: Instances
Protocol: TCP
Port: 80
VPC: Select the same one used above
Health check protocol: HTTP
(because your EC2 web servers respond to HTTP)-
Advanced health check settings:
Healthy threshold: 2 Timeout: 2 seconds Interval: 5 seconds
- Register targets: Select both EC2 instances โ Include as pending โ Create Target Group.
โ Target group created โ ready for backend connections.
๐ Step 4: Finalize NLB Setup
- Back on NLB creation screen โ Refresh Target Group list.
- Choose
demo-tg-nlb
as backend. - Review configuration โ Create Load Balancer.
- Wait until State: active.
๐ง Step 5: Troubleshooting (Unhealthy Targets)
If targets show as Unhealthy, check:
- Go to Target Group โ Targets tab โ status: unhealthy
- Verify EC2 security group inbound rules:
- It currently allows HTTP only from
demo-sg-alb
(Application LB) - You must also allow traffic from NLB SG
โ Fix:
- Go to EC2 โ Security Groups โ launch-wizard-1
- Edit inbound rules:
-
Add new rule:
Type: HTTP Source: demo-sg-nlb
-
(Keep the old โallow from ALBโ rule if both are in use)
- Save rules.
๐ Step 6: Verify Load Balancing
- Wait ~30 seconds for health checks to pass โ status becomes Healthy.
- Copy the DNS name of your NLB (e.g.,
DemoNLB-123456.us-east-1.elb.amazonaws.com
) - Paste in browser โ you should see:
Hello World from ip-xxx-xxx-xxx-xxx
- Refresh multiple times โ each refresh switches between instance responses.
โ
Result:
Traffic alternates between your two EC2 instances โ proving TCP load balancing works.
๐งน Step 7: Clean Up
To avoid charges:
- Delete DemoNLB
- Optionally delete:
- Target group
demo-tg-nlb
- Security group
demo-sg-nlb
๐งฉ Key Takeaways
Concept | Explanation |
---|---|
Layer 4 (TCP/UDP) | NLB operates below HTTP, ideal for raw network traffic |
Static IPs / Elastic IPs | One per AZ, ideal for firewall rules |
Health Checks | Can use TCP, HTTP, or HTTPS |
Security | Must explicitly allow NLB SG in backend EC2 SG |
Performance | Millions of requests per second, microsecond latency |
Troubleshooting Tip | โUnhealthyโ targets usually mean blocked inbound rules |
๐ก Exam + Real-World Insight
- If a system requires static IPs โ Use NLB.
- If traffic uses TCP/UDP โ Use NLB.
- For HTTP-based routing โ Use ALB.
- For hybrid setups โ Chain them: NLB โ ALB โ EC2.
โ๏ธ Gateway Load Balancer (GWLB)
Layer 3 Load Balancer (Network Layer โ IP)
๐ง 1. Concept Overview
Purpose:
The Gateway Load Balancer (GWLB) allows you to deploy, scale, and manage third-party network appliances such as:
- Firewalls
- Intrusion Detection/Prevention Systems (IDS/IPS)
- Deep Packet Inspection (DPI) tools
- Network traffic analyzers
- Custom packet filters or payload modifiers
โ It makes all traffic in your VPC pass through these appliances transparently before reaching applications.
๐งฉ 2. Key Idea: Transparent Traffic Inspection
Without GWLB:
User traffic โ Application Load Balancer โ EC2 app directly.
With GWLB:
User traffic โ Gateway Load Balancer โ Virtual Appliances (firewalls, IDS) โ GWLB โ ALB/Application.
๐ 3. How It Works (Flow Diagram)
Users
โ
Gateway Load Balancer (GWLB)
โ
Target Group (Virtual Appliances โ Firewalls, IDS)
โ
GWLB (return path)
โ
Application Load Balancer / EC2 Application
- GWLB intercepts all traffic.
- Routes traffic to your security appliances for inspection.
- Appliances accept (forward) or drop (block) packets.
- If accepted, traffic returns through GWLB to your app.
- For applications, this process is completely transparent.
๐งฑ 4. Technical Characteristics
Feature | Description |
---|---|
Layer | Layer 3 (Network Layer โ IP) |
Protocol | Uses GENEVE protocol (port 6081) for encapsulation |
Gateway Function | Acts as a transparent network gateway โ single ingress & egress point |
Load Balancing Function | Distributes traffic across appliance targets |
Target Group Types | EC2 instances or private IP addresses |
Supported Targets | - AWS-hosted EC2 appliances - On-premise devices (via private IPs) |
Routing Integration | Automatically updates VPC route tables to redirect traffic through GWLB |
๐งฐ 5. Use Cases
Use Case | Example |
---|---|
Firewalling | All VPC inbound/outbound traffic passes through a firewall fleet |
Intrusion Detection (IDS/IPS) | Detect and block malicious packets before app layer |
Deep Packet Inspection | Analyze packet contents for compliance or malware |
Hybrid Security | Inspect traffic between AWS and on-prem environments |
๐ง 6. Exam Tips (AWS Certified Solutions Architect / SysOps)
Look for these keywords to identify a Gateway Load Balancer question:
Keyword | Points To |
---|---|
โGENEVE protocolโ or โport 6081โ | Gateway Load Balancer |
โThird-party firewall/IDS/DPI appliancesโ | Gateway Load Balancer |
โAll traffic must be inspected before reaching appsโ | Gateway Load Balancer |
โLayer 3 load balancingโ | Gateway Load Balancer |
โTransparent routing or VPC route modificationโ | Gateway Load Balancer |
๐งฉ 7. Summary
Layer | Protocols | Purpose | Typical Targets | Example Services |
---|---|---|---|---|
Layer 3 โ Gateway Load Balancer (GWLB) | IP (GENEVE port 6081) | Inspect or filter all network traffic | Firewalls, IDS/IPS, DPI | Palo Alto, Fortinet, Check Point |
Layer 4 โ Network Load Balancer (NLB) | TCP/UDP/TLS | Raw network traffic distribution | EC2, private IPs | Databases, games, IoT |
Layer 7 โ Application Load Balancer (ALB) | HTTP/HTTPS | Web traffic routing and microservices | EC2, ECS, Lambda | Web apps, APIs |
๐งฉ 8. Key Takeaway
Gateway Load Balancer = Gateway + Load Balancer
- Gateway: Single ingress/egress for traffic in VPC.
- Load Balancer: Distributes traffic among virtual appliances.
- Use GENEVE protocol (port 6081).
- Main use: Routing all traffic through inspection or firewall systems.
๐ง Remember for the Exam
If you see:
โTraffic must go through a firewall or IDS before reaching application servers,โ
โGENEVE protocol,โ
โTransparent inspection,โ
โ The answer is Gateway Load Balancer (GWLB).
๐ช Sticky Sessions (Session Affinity) in AWS Load Balancers
๐ง 1. Concept Overview
Definition:
Sticky sessions (also called session affinity) ensure that a user is consistently routed to the same backend instance for all requests during a session.
Without stickiness:
Requests are distributed evenly across all targets (round-robin).
With stickiness:
Each client โsticksโ to one backend target โ useful for preserving session data stored in memory.
๐งฉ 2. Why Use Sticky Sessions
โ Use Cases
- Applications that store session state locally on EC2 (not in Redis or DynamoDB).
- Web apps requiring user login persistence.
- Shopping carts, dashboards, chat sessions.
โ Avoid when
- You want perfect load distribution (stickiness can cause uneven load).
- The app already uses stateless design or shared storage.
โ๏ธ 3. Supported Load Balancers
Load Balancer Type | Supports Stickiness? | Cookie Name |
---|---|---|
Classic Load Balancer (CLB) | โ | AWSELB |
Application Load Balancer (ALB) | โ |
AWSALB or AWSALBAPP
|
Network Load Balancer (NLB) | โ (via source IP) | No cookie (IP-based) |
๐งพ 4. How Sticky Sessions Work
Example:
You have ALB โ 2 EC2 instances
- Client 1 โ Instance A
- Client 2 โ Instance B
When stickiness is ON:
- Client 1โs next request always goes to Instance A.
- Client 2โs next request always goes to Instance B.
Mechanism:
- The load balancer sends a cookie to the client.
- The client includes the cookie in each subsequent request.
- The load balancer uses that cookie to direct traffic to the same target.
If the cookie expires, a new instance may be chosen.
๐ช 5. Cookie Types
There are two main stickiness cookie types:
Type | Who Generates It | Description | Example Name |
---|---|---|---|
Application-Based Cookie | The application (your backend) | Custom cookie defined by your app; you control its name and duration. | MYCUSTOMCOOKIEAPP |
Duration-Based Cookie | The Load Balancer | Automatically created by ELB with a set expiry time. | ALB: AWSALB / CLB: AWSELB
|
Application-Based Cookie (Custom)
- Created by your app logic.
-
You can specify:
- Cookie name
- Duration
- Attributes
Must not use reserved AWS cookie names:
AWSALB, AWSALBAPP, AWSALBTG
Duration-Based Cookie (Managed)
- Created by the Load Balancer.
- Default lifetime: 1 day, but configurable from 1 second โ 7 days.
- Cookie expires automatically; user might be rebalanced after expiration.
๐ง 6. Enabling Sticky Sessions (Hands-On)
Steps:
- Go to EC2 โ Target Groups
- Select your Target Group (e.g.,
demo-tg-alb
) - Click Actions โ Edit Attributes
- Scroll to Stickiness
- Turn it ON
- Choose cookie type:
- Load Balancerโgenerated (default)
- Applicationโbased (custom cookie)
- Set duration (default = 1 day)
- Save changes.
๐ 7. Verifying Stickiness
- Open your app in the browser.
- Enable Web Developer Tools โ Network โ Cookies tab.
- Make several requests (refresh multiple times).
โ Youโll notice:
- Responses always come from the same EC2 instance.
-
Under Cookies, a new cookie like
AWSALB
appears with:-
Expires:
tomorrow (default 1 day) -
Path:
/
-
Value:
session token.
-
๐งช When the browser includes that cookie in the next request,
the load balancer routes back to the same backend.
โ๏ธ 8. Disabling Stickiness
To revert to normal round-robin load balancing:
- Go back to the Target Group attributes.
- Turn Stickiness โ Off.
- Save changes.
Now each request can hit any backend instance again.
๐ง 9. Key Points to Remember
Concept | Description |
---|---|
Sticky Sessions | Keep the same client bound to the same target |
Mechanism | Load balancer cookie or app cookie |
Default Duration | 1 day (configurable 1sโ7d) |
Main Benefit | Maintains user session consistency |
Main Risk | Uneven load or instance โhot spotsโ |
Where Configured | Target group attributes (per ALB or CLB) |
๐งฉ 10. Exam & Real-World Tip
Exam trigger words:
โUser sessions must remain on the same EC2 instance.โ
โ Answer: Enable sticky sessions (session affinity) on your Load Balancer.
Real-world tip:
If you need session persistence but want balanced load, use shared session storage (e.g., Redis, ElastiCache, DynamoDB) instead of stickiness.
โ๏ธ Cross-Zone Load Balancing in AWS
๐ง 1. What Is Cross-Zone Load Balancing?
Definition:
Cross-zone load balancing ensures that each load balancer node in every Availability Zone (AZ) distributes traffic evenly across all registered targets (EC2 instances) in all AZs.
Without it, each load balancer node only sends traffic to targets within its own AZ.
๐ 2. Example Scenario
๐ก Setup
- 2 Availability Zones (AZs)
- AZ1: 2 EC2 instances
- AZ2: 8 EC2 instances
- Both zones are under the same load balancer.
โ With Cross-Zone Load Balancing (Enabled)
Each load balancer node sends traffic evenly across all 10 instances, regardless of zone.
Traffic flow example:
- Client traffic โ distributed 50/50 between AZ1 and AZ2 load balancer nodes.
- Each node โ evenly distributes requests across all 10 targets.
โก๏ธ Result:
Every EC2 instance gets 10% of total traffic, ensuring perfect balance.
โ Without Cross-Zone Load Balancing (Disabled)
Each load balancer node only sends traffic to targets in its own AZ.
Traffic flow example:
- Client traffic โ split 50/50 between AZ1 and AZ2 load balancer nodes.
- AZ1โs node โ distributes traffic to its 2 instances only โ each gets 25%.
- AZ2โs node โ distributes traffic to its 8 instances only โ each gets 6.25%.
โก๏ธ Result:
AZ1โs instances are overloaded (25% each), while AZ2โs are underutilized.
โ๏ธ 3. How It Works (Visual Concept)
โโโโโโโโโโโโโโโโโโโโโโ
โ Clients โ
โโโโโโโโโโฌโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโ
โ Load Balancer โ
โ (multiple AZ nodes inside) โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โ โ
โ AZ1 (2 instances) AZ2 (8 instances)
โ (25% each w/o CZLB) (6.25% each w/o CZLB)
โ (10% each w/ CZLB) (10% each w/ CZLB)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐งฉ 4. AWS Load Balancer Default Behaviors
Load Balancer Type | Default State | Can Be Changed? | Inter-AZ Data Charges |
---|---|---|---|
Application Load Balancer (ALB) | โ Enabled | Yes (at target group level) | โ No charge |
Network Load Balancer (NLB) | โ Disabled | Yes | ๐ฒ Charged |
Gateway Load Balancer (GWLB) | โ Disabled | Yes | ๐ฒ Charged |
Classic Load Balancer (CLB) | โ Disabled | Yes | โ No charge |
๐งฑ 5. Configuration Locations
Application Load Balancer (ALB):
- Cross-Zone LB โ Enabled by default.
-
Can be overridden per Target Group:
- Inherit from ALB (default)
- Force ON or OFF
Network Load Balancer (NLB):
- Disabled by default.
-
To enable:
- Go to Attributes โ Edit
- Toggle Cross-Zone Load Balancing โ ON
- Warning: โMay incur inter-AZ data charges.โ
Gateway Load Balancer (GWLB):
- Same behavior as NLB (off by default, charges apply when enabled).
๐ฐ 6. Pricing Implications
LB Type | Cross-Zone Behavior | Inter-AZ Cost Impact |
---|---|---|
ALB | Enabled by default | Free (no inter-AZ charge) |
NLB | Optional | Charged per GB of cross-AZ data |
GWLB | Optional | Charged per GB of cross-AZ data |
CLB | Optional | Free (legacy, no charge) |
๐ง 7. When to Enable / Disable
โ Enable Cross-Zone Load Balancing when:
- AZs have unequal numbers of EC2 instances
- You want even traffic distribution
- Cost impact is minimal or acceptable (ALB or low data volume)
โ Disable Cross-Zone Load Balancing when:
- You have balanced infrastructure across AZs
- Want to avoid inter-AZ data charges (NLB or GWLB)
- Need strict AZ isolation for compliance or latency
๐ง 8. Hands-On Practice
- Go to your Load Balancer โ Attributes
- Locate Cross-Zone Load Balancing
- Edit:
- For ALB: verify itโs enabled (default)
- For NLB/GWLB: toggle ON to enable (charges warning)
- At Target Group level, override ALB cross-zone setting if desired.
๐งพ 9. Key Takeaways
Concept | Summary |
---|---|
Cross-Zone Load Balancing | Distributes traffic across all registered targets in all AZs |
Without It | Each LB node only routes to its own AZ targets |
ALB | Enabled by default, free |
NLB & GWLB | Disabled by default, extra cost when enabled |
Use Case | Uneven AZ target distribution or global load spreading |
๐ง 10. Exam Tip
If a question says:
โYou have more EC2 instances in one AZ than another, and want equal traffic distribution.โ
โ Answer: Enable Cross-Zone Load Balancing on your Load Balancer.
If it says:
โYou need static IPs and low latency TCP traffic; avoid cross-AZ data costs.โ
โ Answer: Use NLB and disable cross-zone balancing.
๐ SSL / TLS Certificates in AWS Load Balancing
๐ง 1. What Is SSL / TLS?
Term | Meaning | Status |
---|---|---|
SSL (Secure Sockets Layer) | Original protocol for encrypting connections | Outdated |
TLS (Transport Layer Security) | Modern replacement for SSL | ๐น Current standard |
โ
Both ensure data encryption in transit between client โ server.
This is called โin-flight encryption.โ
๐งฉ 2. Purpose of SSL / TLS in Load Balancing
Goal:
Encrypt all traffic between the client and the load balancer over HTTPS.
Flow Example:
Client โ HTTPS (encrypted) โ Load Balancer
โ HTTP (plain, private VPC) โ EC2 instances
- The Load Balancer terminates SSL/TLS โ decrypts incoming traffic before forwarding to backend targets.
- This process is called SSL Termination.
๐ก Backend communication (within the VPC) can be HTTP for performance,
or HTTPS for end-to-end encryption (optional).
๐งพ 3. Certificates and Management
-
SSL/TLS certificates are digital credentials that:
- Verify the identity of your domain.
- Enable encryption between client and server.
-
Certificates are issued by Certificate Authorities (CAs) such as:
- Comodo, DigiCert, GlobalSign, GoDaddy, Letโs Encrypt, etc.
Certificates expire periodically (e.g., 1 year) and must be renewed.
๐งฐ 4. Managing Certificates in AWS
AWS provides AWS Certificate Manager (ACM) to:
- Automatically provision, store, and renew public certificates.
- Let you upload your own private or third-party certificates.
๐ก When configuring an HTTPS listener on a Load Balancer:
- You must attach at least one default certificate.
- You can attach multiple certificates (for different domains) if SNI is supported.
๐ 5. What Is SNI (Server Name Indication)?
Problem (before SNI):
- Only one SSL certificate per IP address.
- Hosting multiple secure websites on one server required multiple IPs.
Solution:
- SNI (Server Name Indication) allows clients to tell the server which hostname theyโre trying to reach during the SSL handshake.
- The server (load balancer) then chooses the correct certificate dynamically.
โ Result: One ALB/NLB can host multiple domains with different SSL certificates.
๐งญ 6. How SNI Works
1๏ธโฃ Client โ โI want to connect to www.mycorp.comโ
2๏ธโฃ Load Balancer โ Looks up www.mycorp.com
3๏ธโฃ Load Balancer โ Loads correct certificate
4๏ธโฃ Connection established (TLS encrypted)
AWS Implementation Example:
Component | Description |
---|---|
ALB | Has 2 certificates โ www.mycorp.com and domain1.example.com
|
Client 1 | Requests www.mycorp.com โ ALB uses certificate for that domain |
Client 2 | Requests domain1.example.com โ ALB uses the other certificate |
Routing | ALB forwards each to correct target group |
๐ 7. SNI Support by AWS Load Balancers
Load Balancer Type | SNI Support | Certificates Supported |
---|---|---|
Classic Load Balancer (CLB) | โ No | Only one SSL certificate |
Application Load Balancer (ALB) | โ Yes | Multiple certificates per listener |
Network Load Balancer (NLB) | โ Yes | Multiple certificates per listener (TLS listeners only) |
Gateway Load Balancer (GWLB) | โ N/A | Works at Layer 3 (no SSL support) |
๐งฉ 8. Security Policies
When you create an HTTPS listener, you can choose a Security Policy, which defines:
- Supported TLS versions (e.g., TLS 1.2, TLS 1.3)
- Supported cipher suites
- Legacy client compatibility (e.g., old browsers or systems)
๐ก Modern practice: Use only TLS 1.2+ for strong encryption.
๐ก 9. Real-World Example
Architecture:
Client
โ HTTPS (TLS)
Application Load Balancer (SSL termination)
โ HTTP (private)
Target Group (EC2 instances)
Benefits:
- Users get the green padlock (secure site).
- ALB handles certificate management via ACM.
- EC2 servers can stay simple โ no local certificates needed.
๐ง 10. AWS Exam and Interview Tips
Scenario | Correct Answer |
---|---|
โMultiple secure websites on one ALB.โ | Use SNI with multiple certificates. |
โNeed automatic certificate renewal.โ | Use AWS Certificate Manager (ACM). |
โEncrypt traffic between ALB and targets too.โ | Use HTTPS target group or end-to-end encryption. |
โLegacy system supports only old SSL versions.โ | Choose a custom security policy on the listener. |
โOne IP per SSL domain required.โ | (Old case) โ Classic Load Balancer (no SNI). |
๐งพ 11. Key Takeaways
Concept | Summary |
---|---|
SSL/TLS | Encrypts traffic between client and LB |
SSL Termination | Decryption happens at the Load Balancer |
ACM | AWS Certificate Manager handles certificates |
SNI | Enables multiple SSL certs on one LB |
ALB/NLB | Support SNI |
CLB | One certificate only |
Security Policies | Define TLS versions and cipher suites |
๐ Enabling SSL/TLS on Application and Network Load Balancers
๐ง 1. Why Enable SSL/TLS
- To ensure encrypted traffic between clients and your Load Balancer (HTTPS).
- Protects data in transit and gives users a secure connection (padlock icon).
- Implemented using port 443 (HTTPS) and valid SSL/TLS certificates from a trusted authority.
๐งฉ 2. SSL/TLS on the Application Load Balancer (ALB)
Steps to Enable HTTPS Listener:
- Go to your ALB โ Listeners tab
- Click Add listener
-
Protocol:
HTTPS
Port:443
(default) -
Default Action:
โ Forward traffic to a chosen Target Group (e.g.,
demo-tg-alb
)
5. Configure Security Settings
(a) SSL Security Policy
- Defines which TLS versions and cipher suites are supported.
-
Use defaults unless you need to support legacy clients.
Example:-
ELBSecurityPolicy-TLS13-1-2-2021-06
(modern) -
ELBSecurityPolicy-2016-08
(legacy-compatible)
-
(b) SSL/TLS Certificate Source
You have three options:
Source | Description |
---|---|
ACM (AWS Certificate Manager) | Recommended. Automatically renews certificates. |
IAM | Can store certs but not ideal for external domains. |
Import manually | Paste private key, certificate body, and chain directly. |
๐ก Best Practice: Use ACM-issued certificates for your domain (e.g., via Route 53 DNS validation).
6. Result
Once the listener is active:
- All client requests via
https://
are encrypted. - ALB terminates the SSL connection at port 443.
- Backend targets can still receive HTTP (port 80) traffic inside the VPC.
๐ 3. SSL/TLS on the Network Load Balancer (NLB)
Steps to Enable TLS Listener:
- Open your NLB โ Listeners tab
- Click Add listener
-
Protocol:
TLS
Port:443
(default) -
Default Action:
โ Forward to a Target Group (e.g.,
demo-tg-nlb
)
5. Configure Security Settings
(a) Security Policy
-
Defines TLS versions and cipher suites for negotiation.
You can choose policies like:ELBSecurityPolicy-TLS13-1-2-2021-06
ELBSecurityPolicy-FS-1-2-Res-2020-10
(b) Certificate Source
Same three options:
- ACM (recommended)
- IAM (for internal)
- Import manually (if needed)
(c) (Optional) ALPN โ Application-Layer Protocol Negotiation
- Used for modern TLS-based protocols (e.g., HTTP/2, gRPC).
- Usually left at default unless you specifically need it.
๐งฑ 4. Behind the Scenes
- ALB TLS Termination: Decrypts HTTPS โ Forwards plaintext HTTP to backend.
- NLB TLS Termination: Decrypts TCP-level encryption โ Forwards decrypted traffic downstream.
- You can also configure end-to-end encryption (client โ ALB/NLB โ EC2 HTTPS).
๐งพ 5. Key Differences Between ALB and NLB SSL Configuration
Feature | ALB | NLB |
---|---|---|
Layer | Layer 7 (Application) | Layer 4 (Network) |
Listener Protocol | HTTPS | TLS |
Certificate Management | ACM / IAM / Import | ACM / IAM / Import |
Policy Control | SSL/TLS cipher & version policies | TLS cipher & version policies |
Advanced Option | Redirect HTTPโHTTPS | ALPN (App-Layer Protocol Negotiation) |
๐ง 6. AWS Exam / Real-World Tips
Scenario | Best Practice |
---|---|
โWe need to secure our public web app.โ | Use ALB + ACM certificate on port 443. |
โOur backend runs TCP-based apps (e.g., database proxy).โ | Use NLB with TLS listener. |
โWe host multiple domains.โ | Use SNI with multiple certs on ALB/NLB. |
โWe want automatic certificate renewals.โ | Use AWS Certificate Manager (ACM). |
โNeed strong encryption only.โ | Choose a TLS 1.2/1.3 security policy. |
๐งฉ 7. Quick Visual Summary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Clients (HTTPS) โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ Port 443 (TLS)
โโโโโโโโโโโผโโโโโโโโโโโโโ
โ Application LB (ALB) โ โ ACM Certificate + TLS Policy
โโโโโโโโโโโฌโโโโโโโโโโโโโ
โ
โโโโโโโโโโผโโโโโโโโโ
โ EC2 / ECS Tasks โ โ HTTP or HTTPS Target Group
โโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโโโ
โ Network LB (NLB) โ โ TLS Listener + ACM Certificate
โโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ
โโโโโโโโผโโโโโโโ
โ TCP Targets โ
โโโโโโโโโโโโโโโ
๐ Connection Draining / Deregistration Delay
๐ง 1. Concept Overview
Goal:
To gracefully remove EC2 instances (targets) from a Load Balancer without breaking active connections.
When an instance is:
- Manually deregistered,
- Marked unhealthy, or
- Being terminated / replaced (like in Auto Scaling),
โฆthe load balancer needs to stop sending new requests to that instance
but still allow ongoing requests to finish.
This is exactly what Connection Draining (CLB) or Deregistration Delay (ALB/NLB) does.
๐งฉ 2. Two Different Names, Same Purpose
Load Balancer Type | Feature Name | Default Timeout | Setting Location |
---|---|---|---|
Classic Load Balancer (CLB) | Connection Draining | 300 sec (5 min) | ELB attributes |
Application Load Balancer (ALB) | Deregistration Delay | 300 sec (5 min) | Target Group attributes |
Network Load Balancer (NLB) | Deregistration Delay | 300 sec (5 min) | Target Group attributes |
๐งพ 3. How It Works
Letโs imagine 3 EC2 instances behind a Load Balancer:
โโโโโโโโโโโโโโโโโโโโโโโโ
โ Load Balancer โ
โโโโโโโโโโฌโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโ
โ EC2-1 (draining) โ
โ EC2-2 (active) โ
โ EC2-3 (active) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
When EC2-1 enters draining state:
- Existing connections (in-flight requests) โ continue until they finish.
- New connections โ redirected to EC2-2 and EC2-3.
- After the draining timeout, any remaining open connections are terminated.
โ๏ธ 4. Configuration Settings
Parameter | Description |
---|---|
Deregistration Delay Timeout | Time (in seconds) that Load Balancer waits for in-flight requests to finish. |
Range | 1 โ 3600 seconds |
Default | 300 seconds (5 minutes) |
Disable | Set to 0 seconds (no delay). |
๐งฎ 5. Example Behavior
Timeout Value | Use Case | Behavior |
---|---|---|
30 seconds |
Short API calls or static website | Instance drains quickly |
300 seconds (default) |
Balanced workload | Allows moderate in-flight request completion |
600โ3600 seconds |
Long-running uploads, video streams | Gives users time to finish connections |
๐ฆ 6. Real-World Example
- Your Auto Scaling Group triggers a scale-in event.
- One EC2 instance is selected for termination.
- Before stopping, the Load Balancer marks it as โdraining.โ
- All new traffic goes to other instances.
- Current users finish their requests โ instance shuts down gracefully.
๐ก Without connection draining, active users could face:
- Timeout errors
- File upload failures
- Interrupted web sessions
๐งฐ 7. How to Configure in AWS Console
For ALB or NLB:
- Go to EC2 โ Target Groups
- Select your Target Group
- Choose Attributes โ Edit
- Set Deregistration delay timeout (seconds)
- Save changes
For Classic Load Balancer:
- Go to EC2 โ Load Balancers
- Select Classic Load Balancer
- Go to Description โ Edit Attributes
- Enable Connection Draining
- Set timeout (1โ3600 sec)
๐ก 8. CLI Configuration Examples
ALB / NLB (Deregistration Delay):
aws elbv2 modify-target-group-attributes \
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789012:targetgroup/demo-tg/abc123 \
--attributes Key=deregistration_delay.timeout_seconds,Value=120
CLB (Connection Draining):
aws elb modify-load-balancer-attributes \
--load-balancer-name demo-clb \
--load-balancer-attributes \
"{\"ConnectionDraining\":{\"Enabled\":true,\"Timeout\":300}}"
๐ง 9. Exam and Interview Tips
Question | Answer |
---|---|
What is Connection Draining used for? | Allows in-flight requests to complete before instance removal. |
What is it called in ALB/NLB? | Deregistration Delay. |
Default value? | 300 seconds (5 minutes). |
How to disable it? | Set timeout = 0. |
Where to configure in ALB? | In Target Group attributes. |
Scenario: โLong file uploads fail during instance termination.โ | Increase Deregistration Delay value. |
๐งพ 10. Key Takeaways
Concept | Description |
---|---|
Purpose | Gracefully remove instances without breaking connections |
CLB Term | Connection Draining |
ALB/NLB Term | Deregistration Delay |
Default Timeout | 300 seconds |
Configurable Range | 1โ3600 seconds |
Effect | Allows existing requests to complete before shutdown |
Disable | Set to 0 seconds |
โ๏ธ Amazon EC2 Auto Scaling Groups (ASG)
๐ง 1. What Is an Auto Scaling Group?
An Auto Scaling Group (ASG) automatically adds (scales out) or removes (scales in) EC2 instances to match the demand on your application.
โ Main goals:
- Maintain the right number of instances.
- Automatically replace unhealthy instances.
- Optimize costs by removing idle capacity.
- Ensure high availability by balancing load across AZs.
๐ก Key Idea:
ASG uses CloudWatch metrics + scaling policies to decide when to launch or terminate instances.
๐งฉ 2. ASG Core Concepts
Term | Meaning |
---|---|
Scale Out | Add EC2 instances when load increases |
Scale In | Remove EC2 instances when load decreases |
Minimum Size | The smallest number of instances ASG maintains |
Desired Capacity | The number of instances ASG wants to have (starts with this) |
Maximum Size | The largest number of instances ASG can launch |
๐ 3. Example Configuration
Setting | Value | Meaning |
---|---|---|
Min Size | 2 | Always keep at least 2 instances running |
Desired Capacity | 4 | Start with 4 instances |
Max Size | 7 | Never exceed 7 instances |
If load increases:
โ ASG automatically launches up to 7 instances (scale out).
If load decreases:
โ ASG automatically terminates instances (scale in).
๐ 4. How ASG Works with a Load Balancer
Architecture Flow:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Load Balancer โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ
โ Auto Scaling Group โ
โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโดโโโโโโโโโโโโโ
โ EC2 Instances โ
โโโโโโโโโโโโโโโโโโโโโโโโโโ
Behavior:
- New EC2 instances automatically register with the Load Balancer.
- ELB performs health checks and sends the status to the ASG.
- If an instance is unhealthy, ASG terminates and replaces it.
- Traffic is evenly load balanced across all healthy instances.
๐ก Works perfectly with:
- Application Load Balancer (ALB)
- Network Load Balancer (NLB)
๐งฑ 5. Launch Template (or Launch Configuration)
ASG uses a Launch Template that defines how new EC2 instances are created.
Launch Template includes:
- Amazon Machine Image (AMI)
-
Instance Type (e.g.,
t3.micro
) - User Data (startup script)
- EBS volumes
- Security Groups
- Key Pair (SSH access)
- IAM Role for EC2
- Network Subnets / VPC
- Optional Load Balancer attachment
๐ก Launch Configurations are older โ use Launch Templates for all new setups.
๐ 6. Integration with CloudWatch
ASGs rely on CloudWatch Alarms to scale dynamically.
Example Flow:
CloudWatch Metric โ Alarm Triggered โ ASG Scaling Policy โ Adjust Instance Count
Common metrics:
- Average CPU Utilization
- Network In/Out
- Request Count per Target
- Custom Application Metrics
Scale-Out Policy Example:
- If
CPU > 70%
for 5 minutes โ Add 2 instances
Scale-In Policy Example:
- If
CPU < 20%
for 10 minutes โ Remove 1 instance
๐งฎ 7. Example Scenario
Time | Average CPU | ASG Action | Instance Count |
---|---|---|---|
12:00 PM | 20% | Scale In | 2 |
1:00 PM | 75% | Scale Out | 4 |
2:00 PM | 90% | Scale Out | 6 |
4:00 PM | 15% | Scale In | 3 |
ASG keeps scaling dynamically to maintain optimal performance and cost.
๐ฐ 8. Cost Model
Auto Scaling Groups are free โ
you only pay for:
- EC2 instances it launches
- EBS volumes
- Load balancer usage
๐ง 9. Exam & Real-World Tips
Concept | What to Remember |
---|---|
Purpose of ASG | Automatically scale EC2 instances based on demand |
Scale Out | Add instances |
Scale In | Remove instances |
Min/Max/Desired | Controls group size |
Launch Template | Defines instance configuration |
CloudWatch | Triggers scaling policies |
Health Checks | Replace unhealthy instances automatically |
Cost | ASG is free โ pay for underlying EC2 only |
๐งฉ 10. Quick Recap Diagram
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CloudWatch Alarm โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Auto Scaling Group (ASG) โ
โ โโ Min: 2 โ
โ โโ Desired: 4 โ
โ โโ Max: 7 โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโ
โ EC2 Fleet โ โ Instances automatically added/removed
โโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ Load Balancer โ โ Routes traffic to healthy EC2s
โโโโโโโโโโโโโโโโโโโ
โ๏ธ Auto Scaling Group (ASG) โ Hands-On Practice
๐งฉ 1. Pre-Setup: Clean Environment
- Go to EC2 โ Instances
- Terminate all existing EC2 instances โ You should have 0 running before starting.
๐๏ธ 2. Step 1 โ Create an Auto Scaling Group
Go to:
EC2 โ Auto Scaling Groups โ Create Auto Scaling Group
Name: Demo-ASG
Since an ASG needs instructions on how to launch instances,
we must first create a Launch Template.
๐งฐ 3. Step 2 โ Create a Launch Template
-
Name:
my-demo-template
-
Description:
template for ASG practice
- AMI (Amazon Machine Image):
- Choose Amazon Linux 2 (x86, Free Tier Eligible)
-
Instance Type:
t2.micro
-
Key Pair:
EC2-tutorial
(or your existing key) -
Security Group:
launch-wizard-1
(HTTP + SSH allowed) - Storage: Default 8 GB gp2 volume
- User Data: Paste the web-server startup script youโve been using:
-
Instance Type:
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
echo "<h1>Hello world from $(hostname -f)</h1>" > /var/www/html/index.html
- Create Template โ Done
โ Youโve defined how EC2 instances will be launched by the ASG.
๐ 4. Step 3 โ Configure the Auto Scaling Group
-
Select Launch Template:
my-demo-template
- VPC: Choose your default or custom VPC
- Availability Zones: Select at least two or three subnets for multi-AZ distribution.
- Load Balancer Integration:
- Choose Attach to an existing target group
-
Pick your ALB target group (e.g.,
demo-tg-alb
)- Health Checks:
-
Enable both EC2 and ELB health checks
โ ASG will replace any failed instance.- Capacity Settings:
Min capacity: 1
Desired capacity: 1
Max capacity: 1
- Scaling Policies: Skip for now (manual scaling only)
- Notifications / Tags: Optional
- Create Auto Scaling Group
๐ 5. Step 4 โ Observe Instance Launch
Go to:
Auto Scaling Group โ Demo-ASG โ Activity History
- Youโll see a new activity: โLaunching a new EC2 instanceโ
- ASG automatically provisions the instance defined by the Launch Template.
Then check under:
EC2 โ Instances
โ One instance is running.
โ๏ธ 6. Step 5 โ Load Balancer & Health Check Integration
- Go to:
EC2 โ Target Groups โ demo-tg-alb โ Targets
- Youโll see your new instance in initializing state.
- After the User Data completes and health checks pass โ Healthy.
๐ก The instance is now automatically registered to your Application Load Balancer (ALB).
๐ 7. Step 6 โ Test the Web Application
- Copy the ALB DNS name and open it in a browser.
- You should see:
Hello world from ip-xx-xx-xx-xx.ec2.internal
โ Your instance created by the ASG is fully serving traffic through the ALB.
๐ 8. Step 7 โ Manual Scaling (Scale Out)
To test scaling out manually:
- Go to:
Auto Scaling Group โ Demo-ASG โ Edit
- Change:
Desired capacity: 2
Max capacity: 2
- Save changes.
โณ ASG detects that current count = 1, desired = 2 โ launches a new instance.
-
Watch Activity History:
- โLaunching a new EC2 instanceโ
Check Target Group โ Targets:
Both instances become Healthy after bootstrapping.
โ ALB now balances traffic between two EC2 instances.
You can verify by refreshing the ALB DNS โ
youโll see different hostnames/IPs alternating.
๐ 9. Step 8 โ Manual Scaling (Scale In)
Now test scaling in:
- Edit ASG again:
Desired capacity: 1
- Save changes.
ASG will:
- Pick one instance to terminate
- Deregister it from the Target Group
- Retain one healthy EC2 instance
Check Activity History:
Terminating EC2 instance to match desired capacity
โ Traffic now routes only to the remaining instance.
๐ง 10. Key Takeaways
Concept | Description |
---|---|
Launch Template | Defines how ASG creates EC2 instances |
Desired Capacity | Number of instances to maintain |
Scaling Out | Add instances (handle more load) |
Scaling In | Remove instances (reduce cost) |
Load Balancer Integration | ALB automatically distributes traffic & checks health |
Health Check | ASG replaces failed instances automatically |
Cost | ASG is free; pay for EC2 + Load Balancer only |
๐งพ 11. Quick Visual Summary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Application Load Balancerโ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโผโโโโโโโโโโโโ
โ Auto Scaling Group โ
โ โ Min = 1 โ
โ โ Desired = 2 โ
โ โ Max = 2 โ
โโโโโโโโโโโโโฌโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโผโโโโโโโโโโโโ
โ EC2 Instances โ
โ (Web servers w/ UserData) โ
โโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ Auto Scaling Group (ASG) โ Scaling Policies Explained
๐ง 1. Purpose of Scaling Policies
Scaling policies tell the Auto Scaling Group when and how to adjust the number of EC2 instances based on metrics, schedules, or predictions.
Goal:
Keep your application stable, cost-efficient, and responsive to changes in load.
๐ 2. Types of Scaling Policies
A. Dynamic Scaling
Automatically adjusts capacity in response to changing demand.
1๏ธโฃ Target Tracking Scaling (most common & simplest)
- You define a metric and a target value.
- ASG automatically scales in/out to maintain that target.
Example:
Target metric = Average CPU utilization
Target value = 40%
โ ASG keeps average CPU โ 40% by adding/removing instances as needed.
Analogy: Like a thermostat โ you set a temperature (target metric), and it adjusts automatically.
Typical metrics:
AWS/EC2:CPUUtilization
AWS/ApplicationELB:RequestCountPerTarget
-
AWS/EC2:NetworkIn
/NetworkOut
- Custom CloudWatch metrics
2๏ธโฃ Simple / Step Scaling
- You create CloudWatch alarms that trigger scaling actions.
- When an alarm threshold is reached, ASG adds or removes instances.
Example:
If average CPU > 70% โ Add 2 instances
If average CPU < 30% โ Remove 1 instance
Step Scaling enhances this by defining multiple thresholds:
Condition | Action |
---|---|
CPU โฅ 70% | Add 1 instance |
CPU โฅ 85% | Add 2 instances |
CPU โค 20% | Remove 1 instance |
๐ก Useful for gradual adjustments instead of big jumps.
B. Scheduled Scaling
Used when you know in advance that load will increase or decrease.
Example:
- Every Friday at 5 PM โ increase min capacity to 10
- Every Sunday at 2 AM โ decrease min capacity to 2
๐ Useful for predictable workloads, like office hours or batch jobs.
C. Predictive Scaling
Uses machine learning to analyze historical trends and automatically forecast demand.
- AWS forecasts future traffic based on patterns.
- It pre-provisions instances ahead of time to prevent performance drops.
๐ก Ideal for cyclical traffic patterns, such as:
- E-commerce peaks (weekends, holidays)
- Daily business workloads (9 AM โ 5 PM)
๐ 3. Common Scaling Metrics
Metric | Description | When to Use |
---|---|---|
CPUUtilization | Average CPU load across ASG | For compute-intensive apps |
RequestCountPerTarget | Requests handled per target (via ALB) | For web apps / APIs |
NetworkIn / NetworkOut | Data transferred (in bytes) | For upload/download-heavy apps |
Custom Metric | Any app-specific metric pushed to CloudWatch | For special workloads (e.g., queue depth, active users) |
๐งฎ 4. Cooldown Period (Stabilization Delay)
After a scaling activity (adding/removing instances), the ASG enters a cooldown period โ a โquiet timeโ before the next scaling action.
Setting | Description |
---|---|
Default Cooldown | 300 seconds (5 minutes) |
Purpose | Prevents rapid up/down scaling before metrics stabilize |
Disable / Adjust | You can customize or shorten it if using pre-baked AMIs |
๐ง How it works:
- If a scaling action occurs during cooldown โ ignored.
- If no cooldown in progress โ action executed.
Best practice:
Use ready-to-use AMIs (with pre-installed dependencies)
โ new instances become healthy faster โ shorter cooldowns โ quicker scaling response.
๐งฉ 5. Example Scenario
Letโs say your web app has 3 instances and CPU jumps to 80%.
Metric | Rule | Action | Result |
---|---|---|---|
CPU > 70% | Add 2 instances | Scale Out | 5 total |
CPU < 30% | Remove 1 instance | Scale In | 4 total |
CPU stabilizes at 40% | No change | Stable | 4 total |
๐ 6. Recommended Setup Flow
- Enable Detailed Monitoring (1-minute metric intervals)
- Define metric and target value
- Configure Target Tracking Policy
- Adjust Cooldown Period
- Test with manual scaling first
- Gradually enable predictive/scheduled scaling
๐ก 7. Exam & Interview Tips
Question | Answer |
---|---|
Whatโs the easiest scaling policy to use? | Target Tracking Scaling |
Which scaling type uses CloudWatch alarms? | Simple / Step Scaling |
Which one is based on future load forecasts? | Predictive Scaling |
Default cooldown period? | 300 seconds |
How to reduce cooldown? | Use pre-baked AMIs & shorter warm-up time |
Whatโs the most common scaling metric? | Average CPUUtilization |
How to prepare for predictable spikes? | Scheduled Scaling |
๐งพ 8. Visual Summary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CloudWatch Metrics โ
โ (CPU, Requests, Network, Custom) โ
โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Auto Scaling Group (ASG) โ
โ โ Target Tracking Policy โ
โ โ Step/Simple Policy โ
โ โ Scheduled Policy โ
โ โ Predictive Policy โ
โโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ EC2 Instances Adjusted โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ๏ธ Auto Scaling Group (ASG) โ Automatic Scaling Hands-On
๐ง Goal
Set up automatic scaling so your ASG can add or remove EC2 instances automatically based on CPU utilization (or any other metric).
Weโll practice:
- Scheduled scaling
- Predictive scaling
- Dynamic scaling (with Target Tracking)
๐๏ธ 1. Scheduled Scaling
Schedule capacity changes at specific times.
Example use cases:
- You expect heavy traffic during weekends or marketing events
- You want to scale down during off-hours to save cost
Steps:
- Go to your ASG โ Automatic Scaling โ Scheduled actions โ Create
- Define:
- Start time / end time
-
Desired, Min, or Max capacity
- Example:
At Saturday 8 AM, increase min capacity to 10
At Sunday 11 PM, decrease min capacity to 2
โ Used when load is predictable.
๐งฎ 2. Predictive Scaling
Uses machine learning to automatically forecast load and scale ahead of time.
How it works:
- AWS analyzes your appโs historical metrics (like CPU or request counts)
- Builds a forecast for upcoming load
- Schedules scaling before the spike
Setup:
- Choose metric (CPU, ALB RequestCountPerTarget, etc.)
- Define a target value (e.g., 50% CPU)
- AWS automatically handles the rest
๐ก Works best after at least 24 hours of steady metrics โ typically used for apps with repeating patterns (e.g., business hours, daily peaks).
โก 3. Dynamic Scaling (Hands-On)
Automatically adjusts instance count based on real-time metrics.
There are three types:
Type | Description | Example |
---|---|---|
Simple Scaling | Uses one CloudWatch alarm | โIf CPU > 70%, add 1 instanceโ |
Step Scaling | Uses multiple alarm thresholds | โIf CPU > 85%, add 2; if > 70%, add 1โ |
Target Tracking (Recommended) | Automatically maintains a target metric | โKeep average CPU = 40%โ |
๐งฐ Step-by-Step: Target Tracking Policy
- Go to your ASG โ Automatic Scaling โ Add Policy
- Choose Dynamic Scaling Policy
- Select Target Tracking Scaling Policy
- Name it
CPU-TargetTracking
- Metric: Average CPU Utilization
- Target value: 40%
- Leave cooldown at default (300s)
- Save
โ This automatically creates two CloudWatch alarms:
- AlarmHigh โ Scale Out (when CPU > 40%)
- AlarmLow โ Scale In (when CPU < 28%)
๐ฌ 4. Stress Test to Trigger Scaling
Now weโll simulate load to make scaling happen.
Step 1 โ Connect to EC2 Instance
Use EC2 Instance Connect or your SSH key:
ssh -i mykey.pem ec2-user@<public-ip>
Step 2 โ Install stress tool
sudo yum install -y stress
Step 3 โ Generate CPU load
stress -c 4
โ Forces CPU utilization close to 100%.
Step 4 โ Observe scaling
Go to:
EC2 โ Auto Scaling Groups โ Demo-ASG โ Activity history
After a few minutes youโll see:
Launching a new EC2 instance due to target tracking policy
Check under:
Instance management โ Instances
โ New EC2 instances appear (scale-out event)
๐ 5. CloudWatch Alarms in Action
Go to:
CloudWatch โ Alarms
Youโll see:
-
AlarmHigh
โ State: In ALARM (CPU > 40%) -
AlarmLow
โ State: OK or INSUFFICIENT_DATA
Details:
-
AlarmHigh
: triggers scale-out after CPU > 40% for 3 data points (3 min) -
AlarmLow
: triggers scale-in after CPU < 28% for 15 data points (15 min)
๐ 6. Observe Scale-In
Once you stop stressing the CPU:
- Press
Ctrl + C
to stop stress, or reboot instance:
sudo reboot
- CPU utilization drops โ alarmLow activates
- ASG automatically terminates extra instances
Check Activity History:
Terminating EC2 instance to match desired capacity
โ ASG gradually scales back down to the minimum instance count.
๐ 7. Verification
Step | Action | Expected Result |
---|---|---|
Stress CPU | Run stress -c 4
|
CPU โ 100%, triggers scale-out |
Stop stress | Ctrl+C / reboot | CPU โ drops, triggers scale-in |
Check CloudWatch | Two alarms visible |
AlarmHigh and AlarmLow
|
Check ASG activity | History updated | Launch/Terminate events visible |
โ๏ธ 8. Cleanup
When finished:
- Stop stress test (if still running)
- In ASG โ Automatic Scaling, delete your target tracking policy
- Optionally, delete the ASG and launch template to stop all EC2 billing
๐ง 9. Key Takeaways
Concept | Summary |
---|---|
Target Tracking | Simplest, recommended scaling method |
Automatic Scaling | Adds/removes instances based on metrics |
Scaling Alarms | Created automatically by target tracking |
Predictive Scaling | Uses ML to forecast and pre-scale |
Scheduled Scaling | Manual scheduling of capacity changes |
Cooldown Period | Default 300s; prevents rapid oscillation |
Stress Tool | Useful for testing scaling logic |
Detailed Monitoring | Provides 1-minute metric granularity |
๐งพ 10. Visual Summary
CloudWatch Metric (CPU) โโโโบ AlarmHigh / AlarmLow
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Auto Scaling Group (Demo-ASG) โ
โ โข Min: 1 โ
โ โข Max: 3 โ
โ โข Target: 40% CPU โ
โโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโผโโโโโโโโโโ
โ EC2 Instances Auto โ
โ Added / Removed โ
โโโโโโโโโโโโโโโโโโโโโโ
๐ Lecture: Visualizing ASG Metrics in CloudWatch Dashboard
๐ฏ Goal
By the end of this lab, students will:
- Create a CloudWatch Dashboard
- Add ASG metrics (CPU, instance count, network)
- Observe scale in/out events in real time
- Understand how to interpret these graphs for troubleshooting and tuning scaling policies
๐งฉ 1. What Is a CloudWatch Dashboard?
A CloudWatch Dashboard is a customizable view that displays your AWS metrics in one screen.
You can:
- Monitor ASG, EC2, ELB, and CloudWatch Alarms
- View CPU spikes, instance count changes, and traffic load
- Compare multiple metrics side by side
โ This is essential for real-world DevOps monitoring and alerting setups.
โ๏ธ 2. Step-by-Step: Create the Dashboard
- Go to CloudWatch Console
AWS Console โ CloudWatch โ Dashboards
- Click Create Dashboard
- Name it:
ASG-Monitoring-Dashboard
- Choose Line widget (for graphs)
- Click Configure
๐ 3. Add Key Metrics to the Dashboard
Letโs add 4 key widgets that every DevOps engineer should monitor for ASGs.
๐ง Widget 1: Average CPU Utilization
-
Namespace:
AWS/EC2
-
Metric:
CPUUtilization
- Statistic: Average
- Period: 1 minute (requires Detailed Monitoring)
- Filter: Select your Auto Scaling Group instances
- Label: โAverage CPU Utilizationโ
โ This shows how busy your EC2 instances are.
๐งฉ Widget 2: ASG Group Desired, InService, and Pending Instances
-
Namespace:
AWS/AutoScaling
-
Metrics:
GroupDesiredCapacity
GroupInServiceInstances
GroupPendingInstances
Dimensions: Choose your ASG (
Demo-ASG
)Statistic: Average
Label: โASG Capacity Overviewโ
โ Shows when scaling events occur (launch/terminate).
๐ Widget 3: NetworkIn / NetworkOut
-
Namespace:
AWS/EC2
-
Metrics:
NetworkIn
NetworkOut
Statistic: Sum
Period: 1 minute
Label: โNetwork Traffic (bytes)โ
โ Useful for data-heavy applications or detecting high traffic peaks.
๐งฑ Widget 4: Application Load Balancer Request Count
If your ASG is behind an ALB:
-
Namespace:
AWS/ApplicationELB
-
Metric:
RequestCountPerTarget
- Statistic: Sum
-
Dimension: Choose your Target Group (e.g.,
demo-tg-alb
) - Label: โRequests Per Targetโ
โ Helps correlate incoming traffic with scaling actions.
๐ก Optional Widget: CloudWatch Alarms State
- Widget Type: โAlarm Statusโ
-
Select alarms created by your Target Tracking Policy:
AlarmHigh
AlarmLow
Label: โScaling Alarmsโ
โ Visually shows which alarm triggered (red = active).
๐จ 4. Arrange and Save Dashboard
- Drag widgets to organize logically:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Average CPU Utilization (%) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ ASG Capacity Overview (Desired vs InService) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Network Traffic (In/Out Bytes) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Requests Per Target (ALB) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Click Save Dashboard
๐ 5. Test in Real Time
To see the dashboard in action:
- Run the stress test again on one instance:
stress -c 4
- Wait 2โ3 minutes.
- Watch:
- CPUUtilization spike upward
- AlarmHigh trigger
-
ASG Desired / InService Instances increase
- Stop stress test with
Ctrl + C
- Observe:
- Stop stress test with
CPUUtilization drops
AlarmLow triggers
Instances terminate (scale-in)
โ Youโll see the entire auto-scaling process visually.
๐งฎ 6. Understanding the Dashboard
Metric | What It Shows | What To Look For |
---|---|---|
CPU Utilization | Resource stress level | Sudden spikes โ scaling triggers |
Desired / InService | Instance count | Confirms scaling in/out actions |
NetworkIn/Out | Load intensity | High traffic โ possible cause of scale-out |
Requests per Target | User load via ALB | Useful for performance tuning |
Alarm Status | Which threshold triggered | Red (scale out), Green (scale in) |
๐ง 7. Best Practices
Area | Recommendation |
---|---|
Granularity | Enable 1-minute detailed monitoring on ASG |
Metrics | Track both ASG-level and EC2-level metrics |
Naming | Use consistent names (e.g., demo-asg , demo-tg-alb ) |
Alarms | Always have one for scale-out and one for scale-in |
Retention | Keep dashboard open during load testing |
Automation | Optionally export to JSON for IaC (Terraform or CloudFormation) |
๐งพ 8. Example Dashboard JSON (optional)
If you want to create via CLI or CloudFormation:
{
"widgets": [
{
"type": "metric",
"x": 0,
"y": 0,
"width": 24,
"height": 6,
"properties": {
"metrics": [["AWS/EC2", "CPUUtilization", "AutoScalingGroupName", "Demo-ASG"]],
"title": "Average CPU Utilization",
"period": 60,
"stat": "Average"
}
},
{
"type": "metric",
"x": 0,
"y": 6,
"width": 24,
"height": 6,
"properties": {
"metrics": [
["AWS/AutoScaling", "GroupDesiredCapacity", "AutoScalingGroupName", "Demo-ASG"],
["AWS/AutoScaling", "GroupInServiceInstances", "AutoScalingGroupName", "Demo-ASG"]
],
"title": "ASG Capacity Overview"
}
}
]
}
๐ 9. Key Takeaways
Concept | Summary |
---|---|
CloudWatch Dashboard | Custom visualization of ASG performance |
Dynamic scaling visibility | Instantly shows scale events & CPU trends |
Metrics correlation | Links alarms, traffic, and scaling patterns |
Practical DevOps skill | Used in every production-grade AWS setup |
Next Step | Integrate with SNS or Slack alerts for scaling notifications |
Top comments (0)