Monitoring and Auto Scaling
Amazon CloudWatch and EC2 Auto Scaling — observing resources and automating capacity
1. Amazon CloudWatch
Amazon CloudWatch is a monitoring and observability service that monitors your AWS resources and the applications that run on AWS in real time.
CloudWatch Capabilities
- Collect and track metrics — Standard metrics from AWS services, plus custom metrics from your own applications.
- Alarms — Monitor any CloudWatch metric and automatically send a notification to an Amazon SNS topic, or perform an EC2 Auto Scaling or EC2 action.
- Events — Define rules that match changes in your AWS environment and route them to targets for processing, such as Lambda functions, Kinesis streams, ECS tasks, and Step Functions.
CloudWatch Alarm Components
| Component | Description |
|---|---|
| Namespace | Contains the metric, for example AWS/EC2 |
| Metric | The variable to measure, for example CPU Utilization |
| Statistic | Average, sum, minimum, maximum, sample count, or percentile |
| Period | The evaluation period for the alarm |
| Conditions | Threshold comparison: Greater, Greater or Equal, Lower or Equal, or Lower |
| Actions | Send notification to SNS, or perform EC2 Auto Scaling or EC2 action |
2. Amazon EC2 Auto Scaling
Amazon EC2 Auto Scaling helps you maintain application availability by automatically adding or removing EC2 instances according to conditions you define.
Auto Scaling Group
An Auto Scaling group is a collection of EC2 instances that are treated as a logical grouping for automatic scaling and management. You configure three key values:
- Minimum size — The lowest number of instances the group will maintain.
- Desired capacity — The number of instances the group should have.
- Maximum size — The highest number of instances the group will allow.
If you specify scaling policies, EC2 Auto Scaling can launch or terminate instances as demand increases or decreases, staying within the minimum and maximum bounds.
Launch Configuration
A launch configuration is an instance configuration template that defines what you are scaling. It includes:
- Amazon Machine Image (AMI) ID
- Instance type
- IAM role
- Security groups
- Amazon EBS volumes
Scaling Options
| Option | How It Works | Best For |
|---|---|---|
| Maintain current levels | Periodically health-checks running instances. Replaces unhealthy instances automatically. | Always. This is the baseline behavior. |
| Manual scaling | You manually change the minimum, maximum, or desired capacity. | One-off changes or testing. |
| Scheduled scaling | Scaling actions run automatically based on date and time. | Predictable workloads, such as weekly traffic patterns. |
| Dynamic scaling | Scaling policies respond to changing demand in real time, triggered by CloudWatch alarms. | Unpredictable or variable workloads. |
| Predictive scaling | Uses machine learning on your EC2 usage data to predict traffic and scale proactively. | Workloads with daily or weekly patterns. Requires at least one day of historical data. |
How Dynamic Scaling Works
A typical dynamic scaling configuration uses CloudWatch, EC2 Auto Scaling, and Elastic Load Balancing together:
- CloudWatch monitors a metric such as average CPU utilization across your EC2 fleet.
- When the metric breaches a threshold for a specified duration, a CloudWatch alarm triggers.
- The alarm runs an EC2 Auto Scaling policy that launches or terminates instances.
- EC2 Auto Scaling registers new instances with the load balancer.
- The load balancer performs health checks and begins distributing traffic to the new instances.
- The load balancer feeds performance metrics back to CloudWatch, completing the loop.
3. AWS Auto Scaling
AWS Auto Scaling is a separate service from Amazon EC2 Auto Scaling. It monitors your applications and automatically adjusts capacity to maintain steady, predictable performance at the lowest possible cost.
AWS Auto Scaling can build scaling plans for:
- Amazon EC2 instances and Spot Fleets
- Amazon ECS tasks
- Amazon DynamoDB tables and indexes
- Amazon Aurora Replicas
Monitoring and Auto Scaling Quiz
Select one answer per question. You will receive immediate feedback.