All Products
Search
Document Center

Auto Scaling:Automatically add and remove ECS instances from a PolarDB cluster whitelist

Last Updated:Sep 21, 2026

This topic describes how to combine the lifecycle hook feature of Auto Scaling and a CloudOps Orchestration Service (OOS) template to first put Elastic Compute Service (ECS) instances into a Pending state and then automate the task for adding or removing the instance IP addresses to or from the IP address whitelists of PolarDB clusters.

Prerequisites

  • A scaling group is created and is in the Enabled state.

  • A PolarDB cluster is created.

  • A Resource Access Management (RAM) role is created for OOS. The trusted entity of the RAM role must be Alibaba Cloud Service, the trusted service must be CloudOps Orchestration Service, and the RAM role must have the permissions to perform operations on the OOS template. For more information, see Create a RAM role for OOS and grant permissions.

    Note

    In this topic, the OOSServiceRole RAM role is used as an example. You can also use other roles.

Background

Auto Scaling currently supports only the integration with Server Load Balancer (SLB) and ApsaraDB RDS. If you store your application data in a PolarDB cluster, manually updating the cluster IP address whitelist with the private IP addresses of your ECS instances leads to inefficient operation processes. To enhance operational efficiency, you can consider automating updates of the IP address whitelist for your PolarDB cluster by combing the lifecycle hook feature of Auto Scaling and an OOS template.

Procedure

In this example, a public OOS template named ACS-ESS-LifeCycleModifyPolarDBIPWhitelist is used to show how to automate the addition of instance IP addresses to the IP address whitelist of a PolarDB cluster during a scale-out event. Perform the following steps:

Note

If you want to automate the removal of instance IP addresses from the IP address whitelist of your PolarDB cluster, you can create a lifecycle hook for scale-in purposes and apply the lifecycle hook during a scale-in event.

Step 1: Grant a RAM role the permissions on OOS

You must have the permissions to execute OOS templates. The ACS-ESS-LifeCycleModifyPolarDBIPWhitelist template includes ECS, Auto Scaling, and PolarDB resources that are required to perform O&M tasks.

  1. Log on to the RAM console.

  2. Create a policy.

    1. In the left-side navigation pane, choose Permissions > Policies.

    2. On the Policies page, click Create Policy.

    3. On the Create Policy page, click the JSON tab, configure the parameters, and then click OK.

      The following table describes the settings that are used in this example. Any parameters not covered in the following table default to their predefined settings.

      Parameter

      Description

      Name

      Enter ESSHookPolicyForPolarDBWhitelist.

      Policy Document

      Enter the following content:

      {
          "Version": "1",
          "Statement": [
              {
                  "Action": [
                      "ecs:DescribeInstances"
                  ],
                  "Resource": "*",
                  "Effect": "Allow"
              },
              {
                  "Action": [
                      "polardb:DescribeDBClusterAccessWhitelist",
                      "polardb:ModifyDBClusterAccessWhitelist"
                  ],
                  "Resource": "*",
                  "Effect": "Allow"
              },
              {
                  "Action": [
                      "ess:CompleteLifecycleAction"
                  ],
                  "Resource": "*",
                  "Effect": "Allow"
              }
          ]
      }
  3. Attach the policy to the OOSServiceRole RAM role.

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

    2. Find the OOSServiceRole RAM role and click Grant Permission in the Actions column.

      Add the required permissions for the OOSServiceRole RAM role that is assumed by OOS to complete the authorization.

    3. On the Grant Permission page, configure the resource scope and policy, and then click Grant Permission.

      The following table describes the settings that are used in this example. Any parameters not covered in the following table default to their predefined settings.

      Parameter

      Description

      Resource Scope

      Set the value to Account.

      Policies

      Select the following custom policy: ESSHookPolicyForPolarDBWhitelist.

Step 2: Create a lifecycle hook for scale-out purposes and trigger a scale-out event

  1. Log on to the Auto Scaling console.

  2. In the navigation pane on the left, click Scaling Groups.

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

  4. Find the scaling group that you want to manage and open its details page in one of the following ways:

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

    • In the Actions column, click Details.

  5. Create a lifecycle hook.

    1. At the top of the page, click the Event and adhesive hook tab.

    2. Click Create Lifecycle Hook.

    3. Configure the lifecycle hook parameters and click OK.

      The following table describes the settings that are used in this example. Any parameters not covered in the following table default to their predefined settings.

      Parameter

      Description

      Name

      Enter ESSHookForAddPolarDBWhitelist.

      Scaling Activity Type

      Select Scale-Out.

      Timeout Period

      Configure Timeout Period based on your business requirements. In this example, set the value to 300. Unit: seconds.

      Note

      The timeout period is the period of time during which you can perform custom operations on instances. If the timeout period is shorter than the period of time that is required to perform custom operations, the operations may fail. We recommend that you estimate the period of time that is required to perform custom operations on instances and configure Timeout Period based on your estimations.

      Default Execution Policy

      Select Continue.

      Send Notification When Lifecycle Hook Takes Effect

      Configure the following parameters for the template:

      • Notification Method: Select OOS Template.

      • OOS Template Type: Select Public Templates.

      • Select ACS-ESS-LifeCycleModifyPolarDBIPWhitelist.

      In the ACS-ESS-LifeCycleModifyPolarDBIPWhitelist public template, you must also configure the following parameters:

      • dbClusterId: Enter the ID of the PolarDB cluster.

      • modifyMode: Select Append. This value applies to the scale-out event during which Auto Scaling adds the private IP addresses of your ECS instances to the IP address whitelist of the PolarDB cluster.

      • OOSAssumeRole: Select OOSServiceRole. In Step 1, OOSServiceRole is granted the permissions on the ECS, Auto Scaling, and PolarDB resources. OOS obtains the preceding permissions after it assumes the RAM role.

  6. Trigger a scale-out event.

    In this example, a scale-out event is manually triggered by executing a scaling rule. You can also trigger scale-out events by using scheduled or event-triggered tasks.

    Note

    If scaling events are triggered when you manually execute scaling rules, lifecycle hooks take effect. However, lifecycle hooks do not take effect when you manually add or remove ECS instances to or from a scaling group.

    1. Click the Scaling Rules and Event-triggered Tasks tab.

    2. On the Scaling Rules tab, click Create Scaling Rule.

    3. Set the properties for the scaling rule and click OK.

      The following table describes the settings that are used in this example. Any parameters not covered in the following table default to their predefined settings.

      Parameter

      Description

      Rule Name

      Enter Add1.

      Rule Type

      Select Simple Scaling Rule.

      Operation

      Set the value to Add 1 Instances.

    4. In the list of scaling rules, find the Add1 rule that you created and click Recurrently in the Actions column.

    5. Click OK.

    After the scaling rule is executed, Auto Scaling adds one ECS instance to the scaling group. However, the ECS instance enters the Pending Add state because of the ESSHookForAddPolarDBWhitelist lifecycle hook that is in effect. During the timeout period of the lifecycle hook, Auto Scaling notifies OOS to execute the O&M tasks that are defined in the ACS-ESS-LifeCycleModifyPolarDBIPWhitelist public template.

Step 3: Check the IP address whitelist of the PolarDB cluster

  1. Log on to the PolarDB console.

  2. In the navigation pane on the left, click Clusters.

  3. Find the PolarDB cluster and click its ID in the Cluster ID/Name column.

  4. In the navigation pane on the left, click Settings and Management > Cluster Whitelist.

    • If the private IP address of the ECS instance is added to the IP address whitelist of the PolarDB cluster, the ACS-ESS-LifeCycleModifyPolarDBIPWhitelist public template takes effect.

    • If the ECS instance is created but its private IP address is not added to the IP address whitelist of the PolarDB cluster, go to the OOS console to view the execution of the O&M tasks. For more information, see Step 4: (Optional) View the OOS execution.

Step 4: (Optional) View the OOS execution

  1. Log on to the OOS console.

  2. In the left-side navigation pane, choose Automated Task > Task Execution Management.

  3. Find the execution task by time and click Details in the Actions column.

  4. On the execution details page that appears, view the related information.

    For example, you can view the execution ID and status in the Basic Information section. In the Execution Result section, you can click a task node to view its details. For more information, see View the details of an execution.

    Note

    If the execution fails, an error message is displayed on the execution details page.

FAQ

If you fail to execute an O&M task, troubleshoot the issue based on the error message in the execution result. For more information, see FAQ.

The following table describes the common error message.

Error message

Cause

Solution

Forbidden.Unauthorized message: A required authorization for the specified action is not supplied.

You have not authorized Auto Scaling to perform the current action.

Check whether the OOSServiceRole RAM role has the required permissions.

Forbidden.RAM message: User not authorized to operate on the specified resource, or this API doesn't support RAM.

The RAM user or RAM role does not have the permissions to operate the corresponding resources.

Check whether the OOSServiceRole RAM role has the required permissions. For example, you can grant the OOS permissions to the RAM role. Before OOS can manage the resources that are declared in the OOS template, you must grant the required permissions to the RAM role.

LifecycleHookIdAndLifecycleActionToken.Invalid message: The specified lifecycleActionToken and lifecycleActionId you provided does not match any in process lifecycle action.

The ongoing lifecycle hook action has ended or been stopped.

Assess the timeout period of the lifecycle hook to make sure that the O&M tasks specified in the OOS template can be complete within the allotted time limit.