All Products
Search
Document Center

Auto Scaling:Automatically add and remove ECS instances from an AnalyticDB cluster IP address whitelist

Last Updated:Aug 20, 2026

This tutorial shows how to use an Auto Scaling lifecycle hook to place an ECS instance in a wait state and use a CloudOps Orchestration Service (OOS) template to automatically add or remove the instance from the IP address whitelist of an AnalyticDB for MySQL cluster.

Prerequisites

  • A scaling group is created and enabled.

  • An AnalyticDB for MySQL cluster is created.

  • A RAM role is created for the OOS service. For this role, the trusted entity is set to Alibaba Cloud Service and the trusted service is set to CloudOps Orchestration Service. The role must have the permissions to execute OOS templates. For more information, see Set and grant a RAM role for OOS.

    Note

    This topic uses OOSServiceRole as an example RAM role. You can also use a different custom RAM role.

Background

A scaling group can be associated with Server Load Balancer (SLB) instances and ApsaraDB RDS instances, but not with AnalyticDB for MySQL clusters. If your business data is in an AnalyticDB for MySQL cluster, manually managing the IP address whitelist for ECS instances is inefficient. To automate this process, use a lifecycle hook and an OOS template.

Procedure

This tutorial shows how to use the ACS-ESS-LifeCycleModifyAnalyticDBIPWhitelist public OOS template to add an ECS instance to the IP address whitelist of an AnalyticDB for MySQL cluster during a scale-out event. Perform the following steps:

Note

To automatically remove an ECS instance from the IP address whitelist of an AnalyticDB for MySQL cluster during a scale-in event, create a lifecycle hook for the scale-in event and then initiate a scale-in.

Step 1: Grant OOS permissions to a RAM role

You must have permissions to execute OOS templates. The ACS-ESS-LifeCycleModifyAnalyticDBIPWhitelist template requires permissions to perform operations on ECS, Auto Scaling, and AnalyticDB for MySQL resources.

  1. Log on to the Resource Access Management (RAM) console.

  2. Create a policy.

    1. In the navigation pane on the left, click Permission Management > Access Policies.

    2. Click Create Access Policy.

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

      The following table describes the parameters that are used in this tutorial. Use the default values for other parameters.

      Parameter

      Description

      Name

      Enter ESSHookPolicyForAnalyticDBWhitelist.

      Policy Document

      Enter the following content:

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

    1. In the navigation pane on the left, click Identity Management > Roles.

    2. Find OOSServiceRole and click Add Permissions in the Actions column.

      Grant the required permissions to the OOSServiceRole RAM role.

    3. On the Grant Permission page, configure the parameters, and then click OK.

      The following table describes the parameters that are used in this tutorial. Use the default values for other parameters.

      Parameter

      Description

      Authorized scope

      Select Alibaba Cloud Account.

      Policy

      Select the ESSHookPolicyForAnalyticDBWhitelist custom policy.

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

  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 for the scale-out event.

    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 parameters that are used in this tutorial. Use the default values for other parameters.

      Parameter

      Description

      Name

      Enter ESSHookForAddAnalyticDBWhitelist.

      Scaling Activity Type

      Select Scale-Out.

      Timeout Period

      Enter an appropriate timeout period, for example, 300 seconds.

      Note

      The timeout period is the time allowed for the custom action to run. Evaluate the time required for the action and set an appropriate timeout to prevent failures.

      Default Execution Policy

      Select Continue.

      Send Notification When Lifecycle Hook Takes Effect

      Configure the template as follows:

      • Notification Method: Select OOS Template.

      • OOS Template Type: Select Public Templates.

      • Public Template: Select ACS-ESS-LifeCycleModifyAnalyticDBIPWhitelist.

      Configure the execution parameters for ACS-ESS-LifeCycleModifyAnalyticDBIPWhitelist as follows:

      • dbClusterId: Enter the ID of your AnalyticDB for MySQL cluster.

      • modifyMode: Select Append. This applies to a scale-out event and adds the ECS instance to the IP address whitelist of the AnalyticDB for MySQL cluster.

      • RAM role assumed by OOS: Select OOSServiceRole. In the procedure, the OOSServiceRole RAM role has been granted the permissions to manage ECS, Auto Scaling, and AnalyticDB for PostgreSQL. The OOS service assumes this role to obtain these permissions.

  6. Trigger a scale-out event.

    This tutorial uses a manually executed scaling rule as an example, but you can also trigger a scale-out event with a scheduled or event-triggered task.

    Note

    Lifecycle hooks take effect when you manually execute a scaling rule to trigger a scaling activity. However, lifecycle hooks do not take effect when you manually add or remove ECS instances.

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

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

    3. Set the scaling rule properties and click OK.

      The following table describes the parameters that are used in this tutorial. Use the default values for other parameters.

      Parameter

      Description

      Rule Name

      Enter Add1.

      Rule Type

      Select Simple Scaling Rule.

      Operation

      Set this to Add 1 Instances.

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

    5. Click OK.

    After the scaling rule is executed, one ECS instance is automatically created. Because the ESSHookForAddAnalyticDBWhitelist lifecycle hook is created in the scaling group, the instance enters a wait state. OOS is then notified to run the operations defined in the ACS-ESS-LifeCycleModifyAnalyticDBIPWhitelist template.

Step 3: Check the AnalyticDB for MySQL whitelist

  1. Log on to the AnalyticDB for MySQL console.

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

  3. Find the target cluster and click its ID in the Cluster ID/Description column.

  4. In the navigation pane on the left, click Data Security.

    • If the private IP address of the new ECS instance appears in the IP address whitelist of the AnalyticDB for MySQL cluster, the ACS-ESS-LifeCycleModifyAnalyticDBIPWhitelist public template is working correctly.

    • If an ECS instance is created but its private IP address does not appear in the IP address whitelist, check the task's execution status in the OOS console. For more information, see (Optional) Step 4: View OOS execution details.

(Optional) Step 4: View OOS execution details

  1. Log on to the OOS console.

  2. In the navigation pane on the left, choose Automated Tasks > Task Execution Management.

  3. Find the execution based on the start time and click Details in the Actions column.

  4. On the execution details page, view the execution information.

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

    Note

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

FAQ

If an Operation and Maintenance (O&M) task fails, find the cause based on the error message in the execution result. For more information, see FAQ.

Common error messages are as follows:

Error message

Cause

Solution

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

Auto Scaling is not authorized to perform the specified action.

Verify that the required permissions are granted to the OOSServiceRole RAM role.

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 on the corresponding resource.

Verify that the OOSServiceRole RAM role has the required permissions. For example, you can grant the sample permissions for the OOS service to the RAM role. You must add operation permissions to the RAM role to ensure that the OOS service can manage the resources specified in the OOS template.

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

The ongoing lifecycle action has expired or has been aborted.

Evaluate the timeout period of the lifecycle hook to ensure that the O&M tasks defined in the OOS template can be completed within the timeout period.