Mastering AWS Scaling Strategies: EC2 Auto Scaling and Hibernation
Scaling strategies (for example, auto scaling, hibernation)
Mastering AWS Scaling Strategies: EC2 Auto Scaling and Hibernation
This study guide covers the essential scaling strategies required for the AWS Certified Solutions Architect - Associate (SAA-C03) exam, focusing on elasticity, EC2 Auto Scaling, and specialized features like hibernation.
Learning Objectives
After studying this guide, you should be able to:
- Distinguish between horizontal and vertical scaling and identify when to use each.
- Configure EC2 Auto Scaling Groups (ASG) using Launch Templates and scaling policies.
- Compare Simple, Step, and Target Tracking scaling policies.
- Explain the benefits and requirements of EC2 Hibernation for rapid workload resumption.
- Apply cost-optimization strategies using scaling and instance purchasing options.
Key Terms & Glossary
- Horizontal Scaling (Scaling Out/In): Adding or removing instances of a resource (e.g., adding more EC2 instances to a pool).
- Vertical Scaling (Scaling Up/Down): Increasing or decreasing the specifications (CPU, RAM) of an individual resource (e.g., changing a t3.micro to a t3.large).
- Auto Scaling Group (ASG): A logical collection of EC2 instances treated as a single unit for purposes of management and scaling.
- Desired Capacity: The specific number of instances the ASG attempts to maintain at all times.
- Cooldown Period: A configurable setting that prevents the ASG from launching or terminating additional instances before the previous scaling activity takes effect.
The "Big Idea"
The core value of the cloud is Elasticity. In traditional on-premises environments, you must provision for peak load, leading to wasted resources. AWS scaling strategies allow you to match supply to demand in real-time. By automating the growth and shrinkage of your infrastructure, you ensure high availability during traffic spikes and cost savings during quiet periods.
Formula / Concept Box
| Concept | Rule / Formula | Key Parameter |
|---|---|---|
| ASG Logic | Desired Capacity | |
| Percent Change | PercentChangeInCapacity | |
| Cooldown | Default = 300 seconds | Prevents "flapping" |
| Hibernation | RAM state EBS Root Volume | Encrypted EBS required |
Hierarchical Outline
- Scaling Fundamentals
- Vertical Scaling: Limited by the maximum size of a single instance; requires downtime to resize.
- Horizontal Scaling: Preferred for high availability; uses a Load Balancer to distribute traffic.
- EC2 Auto Scaling Components
- Launch Template/Configuration: Defines what to launch (AMI, Instance Type, Security Groups).
- Auto Scaling Group: Defines where (VPC, Subnets) and how many (Min/Max/Desired).
- Dynamic Scaling Policies
- Target Tracking: Most common; maintains a metric (e.g., CPU at 70%).
- Step Scaling: Adjusts capacity based on the size of the alarm breach.
- Simple Scaling: Adjusts capacity by a single value when an alarm is triggered.
- Specialized Strategies
- Scheduled Scaling: Based on known time patterns (e.g., every Monday at 9 AM).
- EC2 Hibernation: Saves RAM state to the EBS root volume; allows for faster "warm" starts than a cold boot.
Visual Anchors
Scaling Logic Flow
Horizontal vs. Vertical Comparison
\begin{tikzpicture}[node distance=2cm] \draw[thick, fill=blue!10] (0,0) rectangle (1.5,1.5) node[midway] {\small EC2}; \draw[->, ultra thick] (0.75, 1.6) -- (0.75, 2.5) node[above] {Vertical (Up)}; \draw[thick, fill=blue!30] (0, 2.6) rectangle (1.5, 4.6) node[midway] {\small Larger EC2};
\begin{scope}[xshift=5cm] \draw[thick, fill=green!10] (0,0) rectangle (1,1) node[midway] {\small EC2}; \draw[->, ultra thick] (1.1, 0.5) -- (2.5, 0.5) node[right] {Horizontal (Out)}; \draw[thick, fill=green!10] (3,0) rectangle (4,1) node[midway] {\small EC2}; \draw[thick, fill=green!10] (4.2,0) rectangle (5.2,1) node[midway] {\small EC2}; \end{scope} \end{tikzpicture}
Definition-Example Pairs
- Scale-Out: Adding more nodes to a system.
- Example: An e-commerce site adding 5 more EC2 instances during a Black Friday sale to handle web traffic.
- Predictive Scaling: Using machine learning to schedule scaling based on historical patterns.
- Example: A news site that sees a spike every morning at 7 AM automatically starts scaling up at 6:30 AM.
- Instance Hibernation: Stopping an instance but preserving the data in memory (RAM).
- Example: A complex data processing application that takes 10 minutes to initialize can use hibernation to resume work in seconds rather than minutes.
Worked Examples
Example 1: Calculating Percent Change
Scenario: An ASG has a current desired capacity of 10 instances. A scaling policy is configured for a PercentChangeInCapacity of 30%. A CloudWatch alarm triggers the policy.
Solution:
- Current = 10.
- Adjustment = $10 \times 0.30 = 3$.
- New Desired Capacity = $10 + 3 = 13 instances.
Example 2: Configuring Hibernation
Scenario: A developer wants to enable hibernation on an existing t3.medium instance with a 20GB unencrypted root volume. Steps to Fix:
- Hibernation cannot be enabled after an instance is launched. The developer must re-create the instance.
- The Root EBS volume must be encrypted to support hibernation.
- The root volume must be large enough to store the RAM contents (20GB\text{ Volume} > 4GB\text{ RAM}$, so this is okay).
Checkpoint Questions
- What happens if an instance becomes unhealthy during a cooldown period?
- Answer: The ASG will replace the unhealthy instance immediately, regardless of the cooldown timer.
- Which scaling policy is best for maintaining a steady aggregate CPU utilization of 60%?
- Answer: Target Tracking Scaling Policy.
- What are the two primary requirements for EC2 Hibernation?
- Answer: The root volume must be an EBS volume (not Instance Store) and it must be encrypted.
- True or False: Vertical scaling is the best choice for highly available, fault-tolerant architectures.
- Answer: False. Horizontal scaling is preferred because it avoids a single point of failure and allows for smoother scaling transitions.
[!TIP] Always use Launch Templates over Launch Configurations for new ASGs, as templates support versioning and newer features like T3 Unlimited and Spot/On-Demand mixing.