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 is in the Enabled state.
-
An AnalyticDB for MySQL 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.
NoteIn this topic, the OOSServiceRole RAM role is used as an example. You can also use other roles.
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:
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.
Log on to the RAM console.
-
Create a policy.
In the left-side navigation pane, choose .
On the Policies page, click Create Policy.
-
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" } ] }
-
Attach the policy to the OOSServiceRole RAM role.
In the left-side navigation pane, choose .
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.
-
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
Log on to the Auto Scaling console.
In the navigation pane on the left, click Scaling Groups.
In the top navigation bar, select a region.
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.
-
Create a lifecycle hook for the scale-out event.
At the top of the page, click the Event and adhesive hook tab.
-
Click Create Lifecycle Hook.
-
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.
NoteThe 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.
-
-
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.
NoteIf scaling activities are triggered when you manually execute scaling rules, lifecycle hooks take effect. Lifecycle hooks do not take effect when you manually add or remove ECS instances to or from a scaling group.
-
Click the Scaling Rules and Event-triggered Tasks tab.
-
On the Scaling Rules tab, click Create Scaling Rule.
-
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.
-
In the scaling rule list, find the Add1 scaling rule that you created and click Recurrently in the Actions column.
-
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
-
Log on to the AnalyticDB for MySQL console.
-
In the navigation pane on the left, click Clusters.
-
Find the target cluster and click its ID in the Cluster ID/Description column.
-
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
Log on to the OOS console.
In the left-side navigation pane, choose .
Find the execution task by time and click Details in the Actions column.
-
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.
NoteIf the execution fails, a corresponding 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. |