Overview of scheduled tasks

更新时间:
复制 MD 格式

A scheduled task executes a scaling rule at a specific time to automatically scale computing resources. This helps you adapt to predictable changes in demand while optimizing costs.

Configuration options

The following table describes the main configuration options for a scheduled task.

Parameter

Description

Executed At

The time when the scheduled task runs.

  • If no recurrence is set, the task runs only once at the specified date and time.

  • If a recurrence is set, this time serves as the execution time for the recurring task.

Important

The execution time must be within 90 days of the task's creation or modification date.

Scaling Group

The target scaling group for the scheduled task. You must select an existing scaling group. For more information, see Overview of scaling groups.

Scaling Method

  • Select Existing Scaling Rule: You can select an existing scaling rule. Scheduled tasks support only simple scaling rules. For more information, see Overview of scaling rules.

  • Configure Number of Instances in Scaling Group: You can directly specify the maximum, minimum, or expected instances for the scaling group. These values override the group's existing settings at the specified time.

    Note
    • If the expected instances feature was not enabled when the scaling group was created, you can only set the maximum instances and minimum instances.

    • If the expected instances feature was enabled when the scaling group was created, you must also set the expected instances when you set the maximum and minimum instances. Otherwise, the scaling activity is rejected.

Simple Scaling Rule

This option appears only if Select Existing Scaling Rule is set to Select Existing Scaling Rule. Select an existing simple scaling rule. For more information, see Configure scaling rules or CreateScalingRule.

Retry Interval (Seconds)

The interval during which Auto Scaling retries a failed scheduled task. Retries help prevent a single failed scaling activity from affecting the task's outcome.

Recurrence

Defines how a scheduled task repeats. You can set a task to run once (no recurrence), or to repeat daily, weekly, or monthly. For more complex schedules, you can use a cron expression. For more information, see Cron expressions.

Note

When you modify a scheduled task, you cannot change its recurrence method to Not Set.

Cron expressions

When you configure a scheduled task in the Auto Scaling console, you can use a cron expression to define its Recurrence.

A cron expression is a string that specifies a time and consists of fields separated by spaces. Scheduled tasks for Auto Scaling support 5-field cron expressions in the format X X X X X, where X is a placeholder for a field. In a cron expression, the fields represent minute, hour, day of the month, month, and day of the week in order. Each field can be a specific value or a special character that has a logical meaning.

When you configure a cron expression for a scheduled task, note the following:

  • Cron expressions use the UTC+0 time zone. You must convert your local time to UTC+0. For example, to run a task at 20:00 China Standard Time (UTC+8), subtract 8 hours and set the cron expression to 0 12 * * ?.

  • A single cron-based scheduled task can run at most once every five minutes.

  • Ensure that the first execution time of the cron expression is earlier than the end time of the recurrence. Otherwise, a parameter error occurs.

Table 1. Fields

Field

Required

Valid values

Special characters

Minute

Yes

0-59

, - / *

Hour

Yes

0-23

, - / *

Day of month

Yes

1-31

, - / * ? L W

Month

Yes

1-12

, - / *

Day of week

Yes

1-7, where 1 represents Sunday.

, - * ? / L #

Table 2. Special characters

Special character

Description

Example

*

Includes all valid values in a field.

In the month field, * means every month. In the day-of-week field, * means every day of the week.

,

Separates items in a list of values.

In the minute field, 5,20 specifies the 5th and 20th minutes.

-

Specifies a range of values.

In the minute field, 5-20 specifies every minute from the 5th to the 20th, inclusive.

/

Specifies increments.

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

?

Indicates no specific value. This character is supported only in the day-of-month and day-of-week fields.

Note

When you specify a value for either the day-of-month or day-of-week field, you must use a ? in the other field to avoid conflicts.

In the day-of-month field, ? indicates no specific day. In the day-of-week field, ? indicates no specific day. For example, the UTC+0 expression 15 10 15 * ? runs the task at 10:15 on the 15th of every month, regardless of the day of the week.

L

An abbreviation for "last". This character is supported only in the day-of-month and day-of-week fields.

Note

When using the L character, do not specify a list or range of values to avoid logical conflicts.

  • In the date field, L represents the last day of a month. In the day-of-week field, L represents the last day of a week.

  • In the day-of-week field, L after a number specifies the last occurrence of that day in the month. For example, 6L means the last Friday of the month.

W

An abbreviation for "weekday". The task runs on the nearest weekday to the specified day. The W character does not cross month boundaries. The LW combination specifies the last weekday of the month.

If you specify 5W in the day-of-month field and the 5th is a Saturday, the task is triggered on the preceding Friday (the 4th). If the 5th is a Sunday, the task is triggered on the following Monday (the 6th). If the 5th is a weekday, the task is triggered on the 5th.

#

Specifies the Nth day of the week in a month. This character is supported only in the day-of-week field. Valid values: 1 to 5.

In the day-of-week field, 4#2 specifies the second Thursday of the month.

Table 3. Examples (UTC+8)

The following table provides examples for the UTC+8 time zone (China Standard Time). Remember to convert your local time to UTC+0 when you set the cron expression.

Cron expression (UTC+0)

Description (UTC+8)

15 10 ? * *

Executes the task at 18:15 every day.

15 9 * * *

Executes the task at 17:15 every day.

0 12 * * ?

Executes the task at 20:00 every day.

0 10,14,16 * * ?

Executes the task at 18:00, 22:00, and 00:00 every day.

15 10 15 * ?

Executes the task at 18:15 on the 15th of every month.

15 10 L * ?

Executes the task at 18:15 on the last day of every month.

15 10 ? * 6L

Executes the task at 18:15 on the last Friday of every month.

15 10 ? * 6#3

Executes the task at 18:15 on the third Friday of every month.

Configure a scheduled task

The following table lists resources for managing scheduled tasks.

Console documentation

Actions

API reference

Configure a scheduled task

Create a scheduled task

CreateScheduledTask

Modify a scheduled task

ModifyScheduledTask

Enable a scheduled task

N/A

Disable a scheduled task

N/A

Delete a scheduled task

DeleteScheduledTask

Note

After you create a scheduled task, you can also call the DescribeScheduledTasks operation to view its details.