Auto Scaling adjusts compute resources based on your policies to handle traffic fluctuations and reduce costs. For unpredictable workloads, use event-triggered tasks to monitor metrics such as CPU utilization and automatically add or remove ECS instances when thresholds are reached.
Scenarios
Scenario description
Service demand fluctuates unpredictably, making it difficult to determine the required number of servers in advance.
For example, a news website experiences unpredictable traffic. When a popular news story breaks, traffic surges. After the story is no longer current, traffic drops.
Solution
Use event-triggered tasks with Cloud Monitor to execute scaling rules when monitoring metrics meet specified conditions, automatically scaling servers based on workload.
Benefits
-
Zero cost for standby servers
Auto Scaling creates and releases ECS instances on demand, eliminating standby servers. You only maintain compute resources required for daily traffic.
-
Automatic scaling
Cloud Monitor tracks load changes in real time, enabling automatic scaling that meets business demands while reducing resource and O&M costs.
Prerequisites
If you are using Auto Scaling for the first time, you must complete the required RAM authorization.
-
The service-linked role AliyunServiceRoleForAutoScaling must be created. For more information, see Service-linked Role.
-
If you use a RAM user, you must grant the AliyunESSFullAccess permission to the RAM user. For more information, see Manage RAM user permissions.
Step 1: Create a scaling group
A scaling group is a core component of Auto Scaling. It is a collection of instances that are managed for the same application scenario. Auto Scaling adds or removes instances from this scaling group.
-
Go to the Scaling Groups page.
Log on to the Auto Scaling console.
-
In the navigation pane on the left, click Scaling Groups.
-
In the top navigation bar, select a region.
-
In the upper-left corner of the page, click Create.
-
On the Create by Form tab, configure the scaling group, and then click Create.
The following configurations are used as an example in this topic. Keep the default values for other configuration items. For more information about how to configure a scaling group, see Create a scaling group.
Configuration Item
Example
Description
Scaling Group Name
test
Enter a name for the scaling group. For more information about the format requirements, see the instructions on the interface.
Type
ECS
Select ECS. This indicates that the instances in the scaling group are ECS instances.
Instance Configuration Source
Create from Scratch
Do not specify a template for automatic instance creation yet. After the scaling group is created, you must create a scaling configuration.
Minimum Number of Instances
1
Set the lower limit for the number of instances in the scaling group. If the current number of instances is below this limit, Auto Scaling automatically adds instances to meet the limit.
Maximum Number of Instances
5
Set the upper limit for the number of instances in the scaling group. If the current number of instances exceeds this limit, Auto Scaling automatically removes instances to meet the limit.
VPC
vpc-bp1jmxxau0lur929p****
Select the VPC to which the ECS instances in the scaling group belong.
vSwitch
vsw-2zeknnyw2ewufbs4z****
vsw-2zesy03h8eaf9fe0l****
Select the vSwitches to which the ECS instances in the scaling group belong. We recommend that you select multiple vSwitches to increase the success rate of scale-out events.
Step 2: Create and enable a scaling configuration and enable the scaling group
A scaling configuration is a configuration template for ECS instances that are added during scale-out events. It includes configuration information such as the billing method, specifications, storage, and network. After you create a scaling configuration, you must enable the scaling configuration and then enable the scaling group.
Find the scaling group that you want to manage and open its details page in one of the following ways:
In the Scaling Group Name/ID column, click the ID of the scaling group.
In the Actions column, click Details.
At the top of the page, click the Scaling Configurations tab.
-
On the Scaling Configurations tab, click Create Scaling Configuration.
-
On the Create Scaling Configuration page, configure the parameters and click Create.
The following configurations are used as an example in this topic. Keep the default values for other configuration items. For more information about scaling configurations, see Create a scaling configuration for ECS instances.
Area
Configuration Item
Example
Description
Basic Information
Scaling Configuration Name
test
Enter a name for the scaling configuration. For more information about the format requirements, see the instructions on the interface.
Billing Method
Pay-As-You-Go
The Auto Scaling service is free of charge, but you are charged for the ECS instances that are added during scale-out events. This topic uses the pay-as-you-go billing method as an example. For more information, see Billing overview.
Instance and Image
Instance Configuration Mode
Specify Instance Properties
Select Specify Instance Properties to configure the specifications of the ECS instances.
Instance Attribute Combination
2 vCPUs, 4 GiB memory, Enterprise-level
Set the vCPU and memory requirements for the ECS instances.
Select Image
Public Image Alibaba Cloud Linux 3.2104 LTS 64-bit
Select the image to deploy the ECS instances. This topic uses a public image as an example. In a real-world scenario, use a custom image where your applications are deployed.
Storage
System Disk
Enterprise SSD, 40 GiB, PL0
Select a system disk for the ECS instances.
Network and Security Group
Public IP Address
Select Assign Public IPv4 Address. The default billing method is pay-by-bandwidth, and the default bandwidth value is 1 Mbit/s.
Select whether to assign a public IP address to the ECS instances as needed. You are charged for the actual outbound public bandwidth used. The bandwidth fees are included in the ECS instance bills.
Security Group
sg-bp18kz60mefsicfg****
Select a security group that you created in advance. To create a security group, see Create a security group.
Management Settings
Logon Credentials
Set After Creation
After the ECS instances are created, manually set passwords for them.
-
In the Scaling Configuration Preview dialog box that appears, confirm the configuration information and click Create Order.
-
In the The scaling configuration is created. dialog box that appears, click Enable.
-
In the Apply Scaling Configuration dialog box that appears, click OK.
NoteYou must enable one scaling configuration within a scaling group. After you enable a scaling configuration, its status changes to Active.
-
In the Enable Scaling Group dialog box that appears, click OK.
After you enable the scaling group, Auto Scaling performs scale-out and scale-in activities based on your configuration.
In this example, the minimum number of instances in the scaling group is 1. Therefore, after the scaling group is enabled, an ECS instance is automatically created based on the scaling configuration. On the details page of the scaling group, click the Instances tab and then the Auto Created tab to view the instance information.

Step 3: Create a scaling rule
A scaling rule specifies the details of a scaling activity, such as the number of ECS instances to add or remove.
-
On the scaling group details page, click the Scaling Rules and Event-triggered Tasks tab, and then click the Scaling Rules tab.
-
Click Create Scaling Rule, configure the scaling rule, and then click OK.
This example uses a simple rule. For more information about how to configure scaling rules, see Configure a scaling rule.
Configuration Item
Description
Rule Name
Enter a name for the rule. For more information about the format requirements, see the instructions on the interface.
Rule Type
This example uses a simple rule. For more information about scaling rules, see Overview of scaling rules.
Operation
Set the number of instances to add or remove when the rule is executed. A maximum of 1,000 instances can be scaled in a single scaling activity.
Cooldown Time
Optional. Unit: seconds. If you do not specify this parameter, the cooldown time of the scaling group is used. For more information, see Cooldown time.
Repeat this step to create a scale-out rule and a scale-in rule. The following table provides example configurations.
Scaling Rule
Example Configuration
Scale-out rule
-
Rule Name: add
-
Rule Type: Simple Rule
-
Operation: Add 1 instance
Scale-in rule
-
Rule Name: remove
-
Rule Type: Simple Rule
-
Operation: Remove 1 instance
-
Step 4: Create an event-triggered task
An event-triggered task monitors metrics in real time. When statistics meet specified conditions, an alert triggers and a scaling rule executes.
-
On the scaling group details page, click the Scaling Rules and Event-triggered Tasks tab, and then click the Event-triggered Task tab.
-
On the Event-triggered Tasks (System) tab, click Create Event-Triggered Task, configure the task, and then click OK.
NoteThis topic uses system metrics. You can also report custom business metrics to create event-triggered tasks. Overview of event-triggered tasks.
Key configurations are described below. Keep default settings for items not mentioned. Configure an event-triggered task.
Configuration Item
Description
Name
Enter a task name. Format requirements are shown on the console.
Alert Condition
Select one or more system-defined metrics as alert conditions. To add metrics, click Add Metric.
Configuration items:
-
Metric: A system monitoring metric. For example, (ECS) CPU Utilization monitors the CPU utilization of ECS instances in the scaling group.
-
Statistical Method: Determines whether the metric exceeds the threshold based on the average, maximum, or minimum value. For example, Average >= 70% triggers an alert when the average CPU utilization in the scaling group reaches 70% or higher.
Alert response rule
Select the scaling rule to execute after an alert is triggered.
Repeat this step to create event-triggered tasks for both the scale-out and scale-in rules. Sample configurations:
Event-triggered Task
Sample Configuration
Alert-triggered scale-out
-
Name: alarm-add
-
Alert Condition: (ECS) CPU Utilization > Average > 70%
-
Rule to Execute: add
Alert-triggered scale-in
-
Name: alarm-remove
-
Alert Condition: (ECS) CPU Utilization > Average < 20%
-
Post-alarm action: remove
-
Verify the automatic scaling effect
After the event-triggered tasks are created, the system monitors metrics in real time and initiates scaling activities when conditions are met.
Expected results:
-
When the CPU utilization of ECS instances in the scaling group is greater than 70%, one ECS instance is automatically added.
-
When the CPU utilization of ECS instances in the scaling group is less than 20%, one ECS instance is automatically removed.
Use a stress testing tool to verify the results:
-
While an event-triggered task runs, go to the scaling group details page. Click the Instances tab, then the Auto Created tab to observe instance count changes.
-
After an event-triggered task completes, go to the scaling group details page. On the Scaling Activities tab, verify the scaling activity executed as expected. Click the activity ID for details.