All Products
Search
Document Center

Serverless App Engine:Manage a scheduled start and stop rule

Last Updated:Sep 03, 2024

You can use the scheduled start and stop feature to start and stop applications in batches by namespace. For example, you can start and stop all applications in a development or test environment at specific points in time. This feature helps you improve the utilization of hardware assets and reduce the cost of idle resources. This topic describes how to manage a scheduled start and stop rule in the SAE console and use crontab expressions.

Preparations

The scheduled start and stop feature takes effect for applications in a namespace. This feature works based on CloudOps Orchestration Service (OOS). You must create the OOSServiceRole RAM role and grant the RAM role the AliyunSAEFullAccess permission to manage SAE. For more information, see Introduction to OOS.

Note

If the OOSServiceRole RAM role already exists, you only need to grant the AliyunSAEFullAccess permission to the RAM role.

  1. Log on to the RAM console as a RAM user who has administrative rights.

  2. In the left-side navigation pane, choose Identities > Roles.

  3. On the Roles page, click Create Role.

  4. On the Create Role page, select Alibaba Cloud Service in the Select Trusted Entity section and click Next.

  5. In the Configure Role step, select Normal Service Role in the Role Type section, enter OOSServiceRole in the RAM Role Name field, select CloudOps Orchestration Service from the Select Trusted Service drop-down list, and then click OK.

  6. In the Finish step, click Add Permissions to RAM role.

  7. In the Select Policy section of the Add Permissions panel, click System Policy. Enter AliyunSAEFullAccess in the search box, click the policy that is displayed to add the policy to the Selected list, and then click OK.

  8. Click Complete.

Create a scheduled start and stop rule

  1. Log on to the SAE console.

  2. In the left-side navigation pane, click Namespaces. In the top navigation bar, select a region. Then, click the name of a namespace.

  3. In the left-side navigation pane, click Scheduled Start and Stop Rules. On the Scheduled Start and Stop Rules page, click Create Scheduled Start and Stop Rule.

  4. In the Create Scheduled Start and Stop Rule panel, configure the parameters and click OK. The following table describes the parameters.

    Parameter

    Description

    Rule Name

    The name of the scheduled start and stop rule. The name must start with a lowercase letter and end with a digit or a lowercase letter. The name can contain only lowercase letters, digits, and hyphens (-) and cannot exceed 63 characters in length.

    Trigger Action

    • Batch Start Applications: starts the selected applications in the current namespace at a time.

    • Batch Stop Applications: stops the selected applications in the current namespace at a time.

    Frequency

    • Execute Only Once: The rule is executed at the specified point in time only once.

    • Scheduled Execution: The rule is regularly executed at the specified point in time on specific dates.

      • By Day: The rule is executed at the specified point in time on specific days per month.

      • By Week: The rule is executed at the specified point in time on specific week days per week.

      • Advanced: Use a crontab expression to define the points in time at which you want to execute the rule. The following section describes the fields in the crontab expression:

        • Minute: the minute. Value range: [0, 59].

        • Hour: the hour. Value range: [0, 23]. The value 0 indicates midnight.

        • Day: the specific day of a month. Value range: [1, 31].

        • Month: the month. Value range: [1, 12] or [JAN, DEC]. You cannot change the field value.

        • Week: the week day. Value range: [1, 7] or [SUN, SAT]. The value 1 indicates Sunday and the value 2 indicates Monday. The values 1 to 7 indicate the seven days of the week from Sunday to Saturday.

          For example, if you want to execute the rule on Tuesday, Thursday, and Saturday, specify 3,5,7 or TUE,THU,SAT in the Week field.

          Note

          [1, 7] indicates the value range. If you specify 1,7, the rule is executed only on Sunday and Saturday.

    Pre-execution Notification Configuration

    Specify the webhook URL of a DingTalk chatbot. SAE sends a notification to the DingTalk group to which the specified DingTalk chatbot belongs each time before the rule is executed. This setting helps you obtain the system O&M information at the earliest opportunity. For more information, see Obtain the webhook URL of a DingTalk chatbot.

    Triggered Applications

    • Start/Stop All Applications: starts or stops all applications in the current namespace.

    • Start/Stop Some Applications: If you select Start/Stop Some Applications, you must select the applications that you want to start or stop in the application list.

    Note

    If you select Start/Stop All Applications, SAE automatically scans the latest application list each time before the rule is executed.

    The created rule is displayed on the Scheduled Start and Stop Rules page. By default, the rule is enabled. You can view, modify, start, enable, disable, or delete the rule.

Use a crontab expression

You can use a crontab expression to define the points in time at which applications are started or stopped and the rule execution regularity in a more flexible manner.

Take note of the following items:

  • You can configure the Day or Week field to specify the time when applications are started or stopped. If you configure a field, you must enter the wildcard ? in the other field. For example, if you want to start or stop applications on the first and second days of each month, enter ? in the Week field.

  • You can use only half-width characters in a crontab expression. For example, you can use asterisks (*) and question marks (?).

  • Separate multiple values with commas (,).

  • Use a hyphen (-) to specify a value range. For example, if you set the Day field to 1-5, the rule is executed on the first to fifth days of each month.

  • The valid values of the Week field range from 1 to 7. The value 1 indicates Sunday and the value 7 indicates Saturday. The values 1 to 7 indicate the seven days of the week from Sunday to Saturday.

Execution time

Configuration method

Crontab expression

22:30:00 on every Monday to Friday

30Minute 22Hour ?Day *Month 2,3,4,5,6Week

30 22 ? * 2,3,4,5,6

00:00:00 on the 5th, 15th and 25th days of each month

0Minute 0Hour 5,15,25Day *Month ?Week

0 0 5,15,25 * ?

FAQ

What do I do if an error message indicating that the OOSServiceRole RAM role does not exist appears after I create the OOSServiceRole RAM role?

Check whether the trust policy of the OOSServiceRole RAM role that you created is the same as the following script. If the trust policy is different from the script, the information that is entered when the role is created is invalid. For example, you select an option other than Alibaba Cloud Service when you configure the Select Trusted Entity parameter. In this case, you must recreate the OOSServiceRole RAM role. For more information, see Preparations.

{
  "Statement": [
    {
      "Action": "sts:AssumeRole",
      "Effect": "Allow",
      "Principal": {
        "Service": [
          "oos.aliyuncs.com"
        ]
      }
    }
  ],
  "Version": "1"
}