You are on page 1of 23

Alibaba Cloud

Auto Scaling

Quick Start

Issue: 20200515
Auto Scaling Quick Start /  Legal disclaimer

Legal disclaimer
Alibaba Cloud reminds you to carefully read and fully understand the terms and conditions
of this legal disclaimer before you read or use this document. If you have read or used this
document, it shall be deemed as your total acceptance of this legal disclaimer.

1. You shall download and obtain this document from the Alibaba Cloud website or other
Alibaba Cloud-authorized channels, and use this document for your own legal business
activities only. The content of this document is considered confidential information of
Alibaba Cloud. You shall strictly abide by the confidentiality obligations. No part of this
document shall be disclosed or provided to any third party for use without the prior
written consent of Alibaba Cloud.

2. No part of this document shall be excerpted, translated, reproduced, transmitted, or


disseminated by any organization, company, or individual in any form or by any means
without the prior written consent of Alibaba Cloud.

3. The content of this document may be changed due to product version upgrades,
adjustments, or other reasons. Alibaba Cloud reserves the right to modify the content
of this document without notice and the updated versions of this document will be
occasionally released through Alibaba Cloud-authorized channels. You shall pay
attention to the version changes of this document as they occur and download and
obtain the most up-to-date version of this document from Alibaba Cloud-authorized
channels.

4. This document serves only as a reference guide for your use of Alibaba Cloud products
and services. Alibaba Cloud provides the document in the context that Alibaba Cloud
products and services are provided on an "as is", "with all faults" and "as available"
basis. Alibaba Cloud makes every effort to provide relevant operational guidance based
on existing technologies. However, Alibaba Cloud hereby makes a clear statement that it
in no way guarantees the accuracy, integrity, applicability, and reliability of the content
of this document, either explicitly or implicitly. Alibaba Cloud shall not bear any liability
for any errors or financial losses incurred by any organizations, companies, or individual
s arising from their download, use, or trust in this document. Alibaba Cloud shall not,
under any circumstances, bear responsibility for any indirect, consequential, exemplary
, incidental, special, or punitive damages, including lost profits arising from the use or
trust in this document, even if Alibaba Cloud has been notified of the possibility of such
a loss.

Issue: 20200515 I
Auto Scaling Quick Start /  Legal disclaimer

5. By law, all the contents in Alibaba Cloud documents, including but not limited to
pictures, architecture design, page layout, and text description, are intellectual property
of Alibaba Cloud and/or its affiliates. This intellectual property includes, but is not
limited to, trademark rights, patent rights, copyrights, and trade secrets. No part of
this document shall be used, modified, reproduced, publicly transmitted, changed,
disseminated, distributed, or published without the prior written consent of Alibaba
Cloud and/or its affiliates. The names owned by Alibaba Cloud shall not be used,
published, or reproduced for marketing, advertising, promotion, or other purposes
without the prior written consent of Alibaba Cloud. The names owned by Alibaba Cloud
include, but are not limited to, "Alibaba Cloud", "Aliyun", "HiChina", and other brands
of Alibaba Cloud and/or its affiliates, which appear separately or in combination, as
well as the auxiliary signs and patterns of the preceding brands, or anything similar
to the company names, trade names, trademarks, product or service names, domain
names, patterns, logos, marks, signs, or special descriptions that third parties identify as
Alibaba Cloud and/or its affiliates.

6. Please contact Alibaba Cloud directly if you discover any errors in this document.

II Issue: 20200515
Auto Scaling Quick Start /  Legal disclaimer

Issue: 20200515 III


Auto Scaling Quick Start /  Document conventions

Document conventions
Style Description Example

A danger notice indicates a


situation that will cause major Danger:
system changes, faults, physical Resetting will result in the loss of
injuries, and other adverse results. user configuration data.

A warning notice indicates a


situation that may cause major Warning:
system changes, faults, physical Restarting will cause business
injuries, and other adverse results. interruption. About 10 minutes
are required to restart an
instance.

A caution notice indicates warning


information, supplementary Notice:
instructions, and other content If the weight is set to 0, the server
that the user must understand. no longer receives new requests.

A note indicates supplemental


instructions, best practices, tips, Note:
and other content. You can use Ctrl + A to select all
files.

> Closing angle brackets are used Click Settings > Network > Set
to indicate a multi-level menu network type.
cascade.

Bold Bold formatting is used for buttons Click OK.


, menus, page names, and other UI
elements.

Courier font Courier font is used for commands. Run the cd /d C:/window
command to enter the Windows
system folder.

Italic Italic formatting is used for bae log list --instanceid


parameters and variables.
Instance_ID

[] or [a|b] This format is used for an optional ipconfig [-all|-t]


value, where only one item can be
selected.

Issue: 20200515 I
Auto Scaling Quick Start /  Document conventions

Style Description Example

{} or {a|b} This format is used for a required switch {active|stand}


value, where only one item can be
selected.

II Issue: 20200515
Auto Scaling Quick Start /  Document conventions

Issue: 20200515 III


Auto Scaling Quick Start /  Contents

Contents

Legal disclaimer......................................................................... I
Document conventions................................................................I
1 Operation procedure............................................................... 1
2 Activate and grant permissions to Auto Scaling........................ 2
3 Create a scaling group and a scaling configuration................... 7
4 Automatically add ECS instances............................................11
5 Automatically remove ECS instances...................................... 13

IV Issue: 20200515
Auto Scaling Quick Start /  1 Operation procedure

1 Operation procedure
This topic introduces the steps to create a complete Auto Scaling solution.

1. Create a scaling group (CreateScalingGroup). Configure the minimum and maximum


number of ECS instances in the scaling group, and select the associated Server Load
Balancer and RDS instances.

2. Create scaling configuration (CreateScalingConfiguration). Configure the ECS instances


attributes for Auto Scaling, such as Image ID and Instance Type.

3. Enable the scaling group with the scaling configuration created in Step 2
(EnableScalingGroup).

4. Create a scaling rule (CreateScalingRule). For example, add N ECS instances.

5. Create a scheduled task (CreateScheduledTask). For example, to trigger the scaling rule
created in Step 4 at 12:00 AM.

6. Create an alarm task (CloudMonitor API PutAlarmRule). For example, to add 1 ECS
instance when the average (it can also be max or min) CPU usage is greater than or
equal to 80%.

Issue: 20200515 1
Auto Scaling Quick Start /  2 Activate and grant permissions to Auto
Scaling

2 Activate and grant permissions to Auto


Scaling
This topic describes how to activate Auto Scaling and grant the permissions for accessing
Alibaba Cloud resources to Auto Scaling.

Context

You must activate Auto Scaling and grant necessary permissions to Auto Scaling when you
use Auto Scaling for the first time. If you have used Auto Scaling before, skip this topic to
create a scaling group and a scaling configuration. For more information, see Create a
scaling group and a scaling configuration.

Step 1: Activate Auto Scaling

1. Log on to the Auto Scaling console.

2. Click Active Auto Scaling.

3. Select I agree with Auto Scaling Agreement of Service and click Enable Now.

Step 2: Grant permissions to Auto Scaling

1. Log on to the Auto Scaling console.

2. Click Authorize.

2 Issue: 20200515
Auto Scaling Quick Start /  2 Activate and grant permissions to Auto
Scaling

3. On the page that appears, select AliyunESSDefaultRole and click Confirm Authorization
Policy.

The Resource Access Management (RAM) role AliyunESSDefaultRole has the permissions
specified in the AliyunESSRolePolicy policy. The content of the AliyunESSRolePolicy policy
is updated from time to time. You can go to the RAM console to view the latest content of
the policy. For more information, see #unique_6. Currently, the policy is as follows:

{
"Version": "1",
"Statement": [
{
"Action": [
"ecs:CreateInstance",
"ecs:RunInstances",
"ecs:StartInstance",
"ecs:AllocatePublicIpAddress",
"ecs:StopInstance",
"ecs:DeleteInstance",
"ecs:DescribeInstances",
"ecs:DescribeInstanceAttribute",
"ecs:ModifyInstanceAttribute",
"ecs:DescribeSecurityGroupAttribute",
"ecs:DescribeImages",
"ecs:DescribeSnapshots",
"ecs:DescribeKeyPairs",
"slb:DescribeLoadBalancerAttribute",
"slb:RemoveBackendServers",
"slb:DescribeHealthStatus",
"slb:AddBackendServers",
"slb:SetBackendServers",
"rds:ModifySecurityIps",
"rds:DescribeDBInstanceAttribute",
"rds:DescribeTaskInfo",
"rds:DescribeDBInstanceIPArrayList"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": [
"vpc:DescribeVpcs",
"vpc:DescribeVSwitches"
],
"Resource": "*",
Issue: 20200515 3
Auto Scaling Quick Start /  2 Activate and grant permissions to Auto
Scaling
"Effect": "Allow"
},
{
"Action": [
"mns:ListTopic",
"mns:ListQueue",
"mns:SendMessage",
"mns:PublishMessage"
],
"Resource": "*",
"Effect": "Allow"
},
{
"Action": "ram:PassRole",
"Resource": "*",
"Effect": "Allow",
"Condition": {
"StringEquals": {
"acs:Service": "ecs.aliyuncs.com"
}
}
}
]
}

For more information about each action, see the API documentation of the
corresponding service. For example, the ecs:RunInstances action allows Auto Scaling to
create one or more Elastic Compute Service (ECS) instances. For more information, see
#unique_7.

• ECS-related actions

Action Description

ecs:RunInstances Creates one or more ECS instances.

ecs:CreateInstance Creates an ECS instance.

ecs:StartInstance Starts an ECS instance.

ecs:AllocatePublicIpAddress Allocates a public network IP address to


an ECS instance.

ecs:StopInstance Stops an ECS instance.

ecs:DeleteInstance Deletes an ECS instance.

ecs:DescribeInstances Queries ECS instances.

ecs:DescribeInstanceAttribute Queries the attributes of an ECS instance.

ecs:ModifyInstanceAttribute Modifies the attributes of an ECS instance


.

ecs:DescribeSecurityGroupAttribute Queries the attributes of a security group.

ecs:DescribeSnapshots Queries all snapshots of an ECS instance


or a disk.

4 Issue: 20200515
Auto Scaling Quick Start /  2 Activate and grant permissions to Auto
Scaling

Action Description

ecs:DescribeKeyPairs Queries one or more Secure Shell (SSH)


key pairs.

• SLB-related actions

Action Description

slb:DescribeLoadBalancerAttribute Queries the information about a Server


Load Balancer (SLB) instance.

slb:RemoveBackendServers Removes back-end servers from an SLB


instance.

slb:DescribeHealthStatus Performs a health check on back-end


servers of an SLB instance.

slb:AddBackendServers Adds back-end servers to an SLB


instance.

slb:SetBackendServers Sets the weights of back-end servers.

• RDS-related actions

Action Description

rds:ModifySecurityIps Modifies the IP address whitelist of


a Relational Database Service (RDS)
instance.

rds:DescribeDBInstanceAttribute Queries the details about an RDS


instance.

rds:DescribeTaskInfo Queries the information about an RDS


task.

rds:DescribeDBInstanceIPArrayList Queries the IP address whitelist of an RDS


instance.

• VPC-related actions

Action Description

vpc:DescribeVpcs Queries Virtual Private Clouds (VPCs).

vpc:DescribeVSwitches Queries VSwitches.

• MNS-related actions

Action Description

mns:ListTopic Queries all Message Service (MNS) topics


under your account.

Issue: 20200515 5
Auto Scaling Quick Start /  2 Activate and grant permissions to Auto
Scaling

Action Description

mns:ListQueue Queries all MNS queues under your


account.

mns:SendMessage Sends a message.

mns:PublishMessage Publishes a message.

What's next
After you activate and grant permissions to Auto Scaling, you can create a scaling group
and a scaling configuration. For more information, see Create a scaling group and a scaling
configuration.

6 Issue: 20200515
Auto Scaling Quick Start /  3 Create a scaling group and a scaling
configuration

3 Create a scaling group and a scaling


configuration
This topic describes how to create a scaling group and a scaling configuration.

Prerequisites
A security group is created. For more information, see #unique_8.

Note:
The security group and the scaling group must be in the same region.

Context

To use Auto Scaling, you must create a scaling group at first. A scaling group is a group
of Elastic Compute Service (ECS) instances that provide the same service. A scaling
configuration is a template used by a scaling group to create ECS instances. After a scaling
group is created, its region cannot be changed. For more information, see #unique_9.

This topic describes how to create a scaling group, create a scaling configuration for the
scaling group, and enable the scaling group. The minimum number of ECS instances in the
scaling group is set to 1.

Step 1: Create a scaling group

In this example, a scaling group is created with simple settings. For more information about
the parameters, see #unique_10.

1. Log on to the Auto Scaling console.

2. In the top navigation bar, select a region.

3. Click Create Scaling Group.

Issue: 20200515 7
Auto Scaling Quick Start /  3 Create a scaling group and a scaling
configuration

4. Set parameters for the scaling group.

a) Enter the name of the scaling group.

In this example, enter MyFirstScalingGroup.

b) Set the maximum number of instances in the scaling group.

In this example, enter 3.

c) Set the minimum number of instances in the scaling group.

In this example, enter 1.

d) Set the cooldown time.

In this example, enter 300.

e) Set the removal policy.

A removal policy contains two levels of priorities. In this example, set the level-1
priority to Earliest Instance Created Using Scaling Configuration and the level-2
priority to Earliest Created Instance.

f) Select a configuration source for creating ECS instances in the scaling group.

In this example, select Custom Scaling Configuration. If you select Launch Template,
the scaling group can be enabled immediately after it is created. Make sure that a
launch template is created in ECS in advance.

g) Select a network type.

In this example, select Classic. If you select VPC, you can set the multi-zone scaling
policy and reclaim mode to scale ECS instances more flexibly. However, you must
create a Virtual Private Cloud (VPC) and a VSwitch in Alibaba Cloud VPC in advance.
For more information, see #unique_11 and #unique_12.

5. Click OK.

6. Click Create Later.

Alternatively, click Create Now. You are redirected to the page for configuring basic
settings of a scaling configuration, as described in Step 2: Create a scaling configuration
and enable the scaling group.

Step 2: Create a scaling configuration and enable the scaling group

In this example, a scaling configuration is created with simple settings. For more
information about the parameters, see #unique_13.

1. Log on to the Auto Scaling console.

2. In the top navigation bar, select a region.

8 Issue: 20200515
Auto Scaling Quick Start /  3 Create a scaling group and a scaling
configuration

3. You can use either of the following methods to open the details page of a scaling group.

• In the Scaling Group Name/ID column, click a scaling group name.

• Click Manage in the Actions column corresponding to a scaling group.

4. In the left-side navigation pane, click Instance Configuration Source.

5. Click Create Scaling Configuration.

6. Complete basic configurations and click Next: System Configurations.

a) Select a billing method.

In this example, select Pay-As-You-Go.

Notice:
You can activate and use Auto Scaling for free. However, if Auto Scaling creates ECS
instances or you add existing ECS instances to scaling groups, you must pay for such
ECS instances based on the ECS pricing. For more information, see #unique_14.

b) Select an instance type.

In this example, select ecs.mn4.small, a balanced ECS instance type.

c) Select an image.

In this example, select the public image CentOS 7.6 64-bit.

d) Set the storage space.

In this example, select a 40 GiB ultra disk as the system disk but select no data disk.

e) Select a billing method and set the peak value for the public bandwidth.

In this example, select the pay-by-traffic method and set the peak value to 1 Mbit/s.

f) Select a security group.

7. Complete the system configurations and click Next: Preview.

In this example, select Set Later for Logon Credentials.

8. Enter the name of the scaling configuration and click Create.

In this example, enter MyFirstScalingConfiguration.

9. Click Enable Configuration.

10.In the Apply Scaling Configuration dialog box that appears, click OK.

11.In the Enable Scaling Group dialog box that appears, click OK.

Result
The minimum number of ECS instances in the scaling group is 1. Therefore, Auto Scaling
automatically creates an ECS instance for the scaling group after it is enabled. You can

Issue: 20200515 9
Auto Scaling Quick Start /  3 Create a scaling group and a scaling
configuration

view the ECS instance in the ECS instance list. For more information, see #unique_15.
The automatically created ECS instance applies configurations specified in the scaling
configuration.

What's next
After the scaling group is enabled, you can create scaling rules for the scaling group and
create scheduled tasks and monitoring tasks to automatically scale ECS instances in the
scaling group. For more information, see the following topics:

• #unique_16

• #unique_17

• #unique_18

10 Issue: 20200515
Auto Scaling Quick Start /  4 Automatically add ECS instances

4 Automatically add ECS instances


Auto Scaling executes a scaling rule to add or remove ECS instances by using scheduled
tasks. This topic describes how to add ECS instances to a scaling group.

Prerequisites
A scaling group and a scaling configuration are created.

Context
This example uses the scaling group MyFirstScalingGroup and scaling configuration
MyFirstScalingConfiguration created in Create a scaling group and a scaling configuration
to show how ECS instances are automatically added. The scaling group already has one
ECS instance.

You can also use scheduled tasks to automatically remove ECS instances. For more
information, see #unique_17.

Step 1: Create a scaling rule

1. Log on to the Auto Scaling console.

2. You can use either of the following methods to open the details page of a scaling group.

• In the Scaling Group Name/ID column, click a scaling group name.

• Click Manage in the Actions column corresponding to a scaling group.

3. In the left-side navigation pane, click Scaling Rules.

4. Click Create Scaling Rule.

5. Set parameters for the scaling rule.

a) Enter the name of the scaling rule.

In this example, enter Add2.

b) Select the type of the scaling rule.

In this example, select Simple Scaling Rule.

c) Specify the operation that you want to perform.

In this example, specify the operation as Add 2 instances.

d) Click Create Scaling Rule.

Step 2: Create a scheduled task

1. In the left-side navigation pane, choose Scaling Tasks > Scheduled Tasks.

Issue: 20200515 11
Auto Scaling Quick Start /  4 Automatically add ECS instances

2. Click Create Scheduled Task.

3. Set parameters for the scheduled task.

a) Enter the name of the task.

In this example, enter ScheduledScalingOut.

b) Enter the description of the task.

In this example, enter "Scheduled to add two instances."

c) Specify the time to execute the task.

In this example, specify the time as five minutes later than the current time. Example:
2019-11-11 16:35.

d) Select the scaling rule.

In this example, select the scaling rule Add2 that is created in step 1.

4. Click OK.

Result
When the time reaches 2019-11-11 16:35, the scheduled task ScheduledScalingOut
automatically executes the scaling rule Add2 to add two ECS instances to the scaling group
MyFirstScalingGroup. For more information, go to the Scaling Activities page.

12 Issue: 20200515
Auto Scaling Quick Start /  5 Automatically remove ECS instances

5 Automatically remove ECS instances


Auto Scaling monitors the ECS instances in a scaling group by using event-triggered tasks
and automatically executes a scaling rule to add or remove ECS instances when an alert is
triggered. This topic describes how to remove ECS instances from a scaling group.

Prerequisites
A scaling group and a scaling configuration are created.

Context
This example uses the scaling group MyFirstScalingGroup created in Create a scaling group
and a scaling configuration to show how ECS instances are automatically removed. After
Auto Scaling adds ECS instances as described in Automatically add ECS instances, the
scaling group has three ECS instances.

You can also monitor other metrics to add ECS instances by using event-triggered tasks
based on your needs. For more information, see #unique_18.

Step 1: Create a scaling rule

1. Log on to the Auto Scaling console.

2. You can use either of the following methods to open the details page of a scaling group.

• In the Scaling Group Name/ID column, click a scaling group name.

• Click Manage in the Actions column corresponding to a scaling group.

3. In the left-side navigation pane, click Scaling Rules.

4. Click Create Scaling Rule.

5. Set parameters for the scaling rule.

a) Enter the name of the scaling rule.

In this example, enter To1.

b) Select the type of the scaling rule.

In this example, select Simple Scaling Rule.

c) Specify the operation that you want to perform.

In this example, specify the operation as Change to 1 Instance.

d) Click Create Scaling Rule.

Issue: 20200515 13
Auto Scaling Quick Start /  5 Automatically remove ECS instances

Step 2: Create an event-triggered task

1. In the left-side navigation pane, choose Scaling Tasks > Event-Triggered tasks.

2. Click Create Event-Triggered Task.

3. Set parameters for the event-triggered task.

a) Enter the name of the task.

In this example, enter EventTriggeredScalingIn.

b) Enter the description of the task.

In this example, enter "Remove ECS instances when the average CPU utilization is less
than 10%."

c) Select the resource to be monitored.

In this example, select MyFirstScalingGroup.

d) Select the monitoring type.

In this example, select System Monitoring.

e) Select the monitoring metrics.

In this example, select CPU.

f) Select the reference period.

In this example, select 1 minute.

g) Specify the condition.

In this example, specify the condition as Average <= 10%.

h) Select the number of times when the condition is met before an alert is triggered.

In this example, select 5 times.

i) Specify the triggering rule.

In this example, select the scaling rule To1 that is created in step 1.

4. Click OK.

Result
The event-triggered task EventTriggeredScalingIn monitors the average CPU utilization of
the three ECS instances in the scaling group MyFirstScalingGroup. The monitoring metric
is calculated once every one minute. If the average CPU utilization is less than or equal to
10% for five times, an alert is triggered. The event-triggered task EventTriggeredScalingIn
automatically executes the scaling rule To1 to adjust the number of ECS instances in the
scaling group MyFirstScalingGroup to one. For more information, go to the Scaling Activities
page.

14 Issue: 20200515
Auto Scaling Quick Start /  5 Automatically remove ECS instances

Issue: 20200515 15

You might also like