All Products
Search
Document Center

Auto Scaling:Overview

Last Updated:Nov 22, 2023

Event-triggered tasks integrate the features of Auto Scaling and CloudMonitor. You can create event-triggered tasks to dynamically manage scaling groups. Similar to scheduled tasks, event-triggered tasks execute specified scaling rules to trigger scaling activities. This way, instances in scaling groups can be automatically scaled.

Introduction

You must specify the metrics that you want to monitor in event-triggered tasks. The system collects the metric data in real time. When the alert conditions are met, the system triggers alerts and executes the specified scaling rules. You can use event-triggered tasks to dynamically adjust the number of instances. This ensures that the changing requirements are met and the metric values are maintained within the expected range. You can create the following types of event-triggered tasks in the Auto Scaling console:

Scheduled tasks execute specified scaling rules as scheduled. If your business has obvious patterns or you can predict the peak hours, you can create scheduled tasks to execute scaling rules. For more information, see Overview of scheduled tasks. If your business has an outburst of traffic or you cannot predict the peak hours, scheduled tasks cannot meet your business requirements. In this case, you can create event-triggered tasks to enable flexible execution of scaling rules. Even-triggered tasks monitor your business workloads in real time and trigger the execution of scale-out rules during peak hours to provide more instances and the execution of scale-in rules during off-peak hours to remove excess instances. This allows you to run your business without interruption and minimize resource costs.

Limits

  • If you do not specify an expected number of instances for your scaling group, Auto Scaling cannot execute other scaling activities for the scaling group when a non-parallel scaling activity is being executed. For more information, see Expected number of instances.

  • Event-triggered tasks cannot execute scaling rules during the cooldown period.

    In most cases, Auto Scaling requires a few minutes to add Elastic Compute Service (ECS) instances or elastic container instances to a scaling group, start the instances, deploy services, and collect metric values. We recommend that you specify the cooldown period based on your business requirements. This way, you can prevent the scaling rules from being repeatedly triggered when the metric data of new instances is missing.

  • By default, an event-triggered task has a one-minute statistical period. During the minute, no more scaling rules are triggered.

Cron expression

When you create an event-triggered task in the Auto Scaling console, you can set the Effective Period parameter to Cron Expression.

A cron expression is a string that represents a schedule. The string consists of multiple fields that are separated by spaces and describe individual details of the schedule. An event-triggered task supports a cron expression that consists of five fields in the X X X X X format. X is a placeholder for a field. The fields in a cron expression represent seconds, minutes, hours, days, and months. Each field can be a definite value or a special character that has logical meaning.

When you configure a cron expression for an event-triggered task, take note of the following items:

  • Cron expressions are in UTC+0. When you configure a cron expression, you must convert the local time to UTC+0. For example, the time in China is in UTC+8. If you are in China and you want to execute your event-triggered task between 01:00:00 and 02:59:00 every day, you must subtract 8 hours from the time range. In this case, you must set the cron expression to * * 17-18 * *.

  • If an alert is triggered outside the effective period of an event-triggered task, the event-triggered task enters the Alert state but does not execute the specified scaling rule.

Table 1. Field values

Field

Required

Value range

Special character

Second

Yes

0 to 59

, - / *

Minute

Yes

0 to 59

, - / *

Hour

Yes

0 to 23

, - / *

Day

Yes

1 to 31

, - / * L W

Month

Yes

1 to 12

, - / *

Table 2. Special characters

Special character

Description

Example

*

All valid field values

In the Month field, an asterisk (*) specifies every month.

,

Enumerated values

In the Minute field, 5,20 indicates the fifth and twentieth minutes.

-

Range values

In the Minute field, 5-20 specifies that the task is triggered once every minute from the fifth minute to the twentieth minute.

/

Increments

In the Minute field, 0/15 specifies every 15 minutes starting from the zeroth minute. 3/20 specifies every 20 minutes starting from the third minute.

L

The L character indicates the last day. Only the Day field supports this character.

Note

To prevent logic errors, do not specify a list or range when you use the L character.

In the Day field, L specifies the last day of a month.

W

The W character indicates the weekday that is nearest to the specified day of the month. The workday that the W character indicates is in the same month as the specified day.

If 5W is specified in the Day field and the fifth day of the month is a Saturday, the task is triggered on the nearest weekday, which is Friday, the fourth day of the month. If the fifth day of the month is a Sunday, the task is triggered on the nearest weekday which is Monday, the sixth day of the month. If the fifth day of the month is a weekday, the task is triggered on the fifth day of the month.

Table 4. Sample cron expressions

The following table provides examples of cron expressions in UTC+0. These cron expressions have different meanings. When you configure a cron expression, you must convert the local time to UTC+0.

Cron expression

Description

* * * * *

Effective all the time.

* 0-30 1-2 * *

Effective between 01:00:00 and 01:30:00 and between 02:00:00 and 02:30:00 every day.

* * 0,2 * *

Effective between 00:00:00 and 00:59:00 and between 02:00:00 and 02:59:00 every day.

* * 1 1/2 *

Effective between 01:00:00 and 01:59:00 every two days staring from the first day of each month. For example, the first two effective time ranges of each month are between 01:00:00 and 01:59:00 on the first day of each month and between 01:00:00 and 01:59:00 on the third day of each month.

* * 1 L *

Effective between 01:00:00 and 01:59:00 on the last day of each month.

* * 1 5W *

Effective on different days based on whether the fifth day of each month is a weekday.

  • If the fifth day of a month is a weekday, the event-triggered task is effective between 01:00:00 and 01:59:00 on the fifth day of the month.

  • If the fifth day of a month is Saturday, the event-triggered task is effective between 01:00:00 and 01:59:00 on the fourth day of the month.

  • If the fifth day of a month is Sunday, the event-triggered task is effective between 01:00:00 and 01:59:00 on the sixth day of the month.

Manage an event-triggered task

The following table describes the operations that you can perform on event-triggered tasks in different scenarios and provides relevant links.

User guide

Description

API reference

Manage event-triggered tasks

Create an event-triggered task.

CreateAlarm

View an event-triggered task.

DescribeAlarms

Modify or delete an event-triggered task.

Disable or enable an event-triggered task.