All Products
Search
Document Center

Auto Scaling:CreateScheduledTask

Last Updated:Apr 26, 2024

Creates a scheduled task. A scheduled task is a type of predefined scaling task that enables automatic execution of a specific scaling rule at a specified point in time. You can call the CreateScheduledTask operation to create a scheduled task to implement automatic scaling of computing resources. This ensures your business continuity and minimizes resource costs.

Usage notes

  • If a scheduled task fails as a result of an active scaling activity in the scaling group or disabled scaling group, the scheduled task is automatically retried during the time window specified by LaunchExpirationTime. If the automatic retry fails, the scheduled task is disregarded at its designated execution time.

  • If several scheduled tasks concurrently attempt to execute the same scaling rule for a scaling group, the following rules apply:

    • Scaling groups with the Expected Number of Instances configured: The scaling activities incurred by the scheduled tasks are parallel scaling activities. In a proximate time window, Auto Scaling can trigger several scheduled tasks and then execute multiple parallel scaling activities at the same time.

    • Scaling groups with the Expected Number of Instances not configured: The scaling activity incurred by the earliest scheduled task is executed. Considering that a scaling group allows for no more than one ongoing scaling activity simultaneously, other scheduled tasks will spontaneously invoke retries within the time window specified by LaunchExpirationTime. Upon completion of the first scheduled task, any retries invoked by other tasks within the time window specified by LaunchExpirationTime lead to continuous enforcement of the scaling rule, with each iteration generating a distinct scaling activity.

  • You can use one of the following methods to specify the scaling mode for a scheduled task:

    • ScheduledAction: Specify an existing scaling rule that you want Auto Scaling to execute when the scheduled task is triggered.

    • ScalingGroupId: Specify the minimum number, maximum number, or expected number of instances for the scaling group for which you create the scheduled task.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter

Type

Required

Example

Description

Action

String

Yes

CreateScheduledTask

The operation that you want to perform. Set the value to CreateScheduledTask.

RegionId

String

Yes

cn-qingdao

The region ID of the scheduled task.

ScheduledTaskName

String

No

scheduled****

The name of the scheduled task. The name must be 2 to 64 characters in length, and can contain letters, digits, underscores (_), hyphens (-), and periods (.). It must start with a letter or digit. The name of a scheduled task must be unique in the region and within the Alibaba Cloud account.

If you do not specify this parameter, the value of ScheduledTaskId is used.

Description

String

No

Test scheduled task.

The description of the scheduled task. The description must be 2 to 200 characters in length.

ScheduledAction

String

No

ari:acs:ess:cn-hangzhou:140692647****:scalingrule/asr-bp12tcnol686y1ik****

The scaling rule that you want to execute when the scheduled task is triggered. Specify the unique identifier of the scaling rule.

If you specify this parameter, you must use ScheduledAction to specify an existing scaling rule in the scheduled task.

Note

If you specify ScheduledAction, you cannot specify ScalingGroupId.

RecurrenceEndTime

String

No

2014-08-17T16:55Z

The end time of the scheduled task.

Specify the time in the ISO 8601 standard in the YYYY-MM-DDThh:mmZ format. The scheduled task must end no later than 365 days after you create it.

LaunchTime

String

No

2014-08-17T16:52Z

The start time of the scheduled task.

Specify the time in the ISO 8601 standard in the YYYY-MM-DDThh:mmZ format. The scheduled task must start no later than 90 days after you create it.

  • If you specify RecurrenceType, the scheduled task is repeatedly executed at the point in time that is specified by LaunchTime.

  • If you do not specify RecurrenceType, the scheduled task is executed only once at the time point that is specified by LaunchTime.

RecurrenceType

String

No

Daily

The interval at which the scheduled task is repeatedly executed. Valid values:

  • Daily: The scheduled task is executed once every specified number of days.

  • Weekly: The scheduled task is executed on each specified day of a week.

  • Monthly: The scheduled task is executed on each specified day of a month.

  • Cron: The scheduled task is executed based on the specified cron expression.

If you specify RecurrenceType, you must also specify RecurrenceValue.

RecurrenceValue

String

No

1

The number of times the scheduled task is repeatedly executed.

  • If you set RecurrenceType to Daily, you can specify only one value for this parameter. Valid values: 1 to 31.

  • If you set RecurrenceType to Weekly, you can specify multiple values for this parameter. Separate the values with commas (,). For example, the values that correspond to Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, and Saturday are 0, 1, 2, 3, 4, 5, and 6.

  • If you set RecurrenceType to Monthly, you can specify two values in the A-B format. Valid values of A and B: 1 to 31. B must be greater than or equal to A.

  • If you set RecurrenceType to Cron, you can specify a cron expression. A cron expression is written in UTC time and consists of the following fields: minute, hour, day, month, and week. The expression can contain the letters L and W and the following wildcard characters: commas (,), question marks (?), hyphens (-), asterisks (*), number signs (#), and forward slashes (/).

If you specify RecurrenceType, you must also specify RecurrenceValue.

TaskEnabled

Boolean

No

true

Specifies whether to enable the scheduled task.

  • true

  • false

Default value: true.

LaunchExpirationTime

Integer

No

600

The time window during which the scheduled task invokes a retry upon encountering failures. Unit: seconds. Valid values: 0 to 1800.

Default value: 600.

MinValue

Integer

No

0

The minimum number of instances in the scaling group if you use ScalingGroupId to specify the scaling mode of the scheduled task.

MaxValue

Integer

No

10

The maximum number of instances in the scaling group if you use ScalingGroupId to specify the scaling mode of the scheduled task.

DesiredCapacity

Integer

No

10

The expected number of instances in the scaling group if you use ScalingGroupId to specify the scaling mode of the scheduled task.

Note

This parameter takes effect only if you specify DesiredCapacity when you create the scaling group.

ScalingGroupId

String

No

asg-bp18p2yfxow2dloq****

The ID of the scaling group for which the scheduled task takes effect.

If you specify this parameter, you must also specify at least one of the following parameters: MinValue, MaxValue, and DesiredCapacity.

Note

If you specify ScalingGroupId, you cannot specify ScheduledAction.

Response parameters

Parameter

Type

Example

Description

ScheduledTaskId

String

edRtShc57WGXdt8TlPbr****

The system-generated unique identifier for the scheduled task at the global level.

RequestId

String

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

The request ID.

Examples

Sample requests

http(s)://ess.aliyuncs.com/?Action=CreateScheduledTask
&RegionId=cn-qingdao
&ScheduledTaskName=scheduled****
&Description=Test scheduled task.
&ScheduledAction=ari:acs:ess:cn-hangzhou:140692647****:scalingrule/asr-bp12tcnol686y1ik****
&RecurrenceEndTime=2014-08-17T16:55Z
&LaunchTime=2014-08-17T16:52Z
&RecurrenceType=Daily
&RecurrenceValue=1
&TaskEnabled=true
&LaunchExpirationTime=600
&MinValue=0
&MaxValue=10
&DesiredCapacity=10
&ScalingGroupId=asg-bp18p2yfxow2dloq****
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateScheduledTaskResponse>
    <ScheduledTaskId>edRtShc57WGXdt8TlPbr****</ScheduledTaskId>
    <RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3****</RequestId>
</CreateScheduledTaskResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "ScheduledTaskId" : "edRtShc57WGXdt8TlPbr****",
  "RequestId" : "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****"
}

Error codes

For a list of error codes, see Service error codes.

HTTP status code

Error code

Error message

Description

404

InvalidRegionId.NotFound

The specified region does not exist.

The specified region does not exist.

400

InvalidScheduledTaskName.Duplicate

The specified value of parameter ScheduledTaskName is duplicated.

A scheduled task with the given name already exists.

400

QuotaExceeded.ScheduledTask

Scheduled task quota exceeded.

The current account has reached its maximum capacity for scheduled tasks.

400

ScheduledAction.RegionMismatch

The specified scheduled task and the specified scheduled action are not in the same Region.

The specified scaling rule and the specified scheduled task are located in different regions.