This tutorial describes how to use an Auto Scaling lifecycle hook to put an ECS instance on hold and use an CloudOps Orchestration Service (OOS) template to automatically add the instance to or remove it from a Tair instance whitelist.
Prerequisites
A scaling group is created and enabled.
A Tair instance 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.
NoteThis 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 cannot be associated with Tair instances. If you store business data on a Tair instance, manually adding ECS instances to or removing them from the Tair instance whitelist is inefficient. You can use lifecycle hooks and OOS templates to automatically add ECS instances to and remove them from the Tair instance whitelist.
Procedure
This tutorial shows how to use the public OOS template ACS-ESS-LifeCycleModifyRedisIPWhitelist to add an ECS instance to a Tair instance whitelist during a scale-out.
To remove an ECS instance from a Tair instance whitelist during a scale-in, create a lifecycle hook for scale-in activities and then trigger a scale-in.
Step 1: Grant permissions to the OOS RAM role
Executing the ACS-ESS-LifeCycleModifyRedisIPWhitelist OOS template requires permissions for the involved Elastic Compute Service, Auto Scaling, and Tair (Redis OSS-compatible) resources.
Log on to the Resource Access Management (RAM) console.
Create a permission policy.
In the navigation pane on the left, click .
Click Create Access Policy.
On the Create Policy page, click the JSON Editor tab, configure the parameters, and then click OK.
The following table describes the parameters. Use the default values for the parameters that are not mentioned.
Parameter
Description
Name
Enter
ESSHookPolicyForRedisWhitelist.Policy Document
Enter the following content:
{ "Version": "1", "Statement": [ { "Action": [ "ecs:DescribeInstances" ], "Resource": "*", "Effect": "Allow" }, { "Action": [ "kvstore:ModifySecurityIps" ], "Resource": "*", "Effect": "Allow" }, { "Action": [ "ess:CompleteLifecycleAction" ], "Resource": "*", "Effect": "Allow" } ] }
Attach the permission policy to the OOSServiceRole RAM role.
In the navigation pane on the left, click .
Find OOSServiceRole and click Add Permissions in the Actions column.
Grant the required permissions to the OOSServiceRole RAM role.
On the Grant Permission page, configure the authorization scope and permissions, and then click OK.
The following table describes the parameters. Use the default values for the parameters that are not mentioned.
Parameter
Description
Resource Range
Select Account.
Policies
Attach the custom policy named
ESSHookPolicyForRedisWhitelist.
Step 2: Create and trigger a scale-out hook
When creating a lifecycle hook, select OOS Template as the notification method and configure the required parameters. This ensures an ECS instance is automatically added to the Tair instance whitelist when a scale-out is triggered.
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.
At the top of the page, click the Event and adhesive hook tab.
Click Create Lifecycle Hook.
Configure the lifecycle hook and click OK.
The following table describes the parameters. Use the default values for the parameters that are not mentioned.
Parameter
Description
Name
Enter
ESSHookForAddRedisWhitelist.Scaling Activity Type
Select Scale-Out.
Timeout Period
Enter an appropriate timeout period, such as 300 seconds.
NoteThe timeout period is the time available to perform custom actions. If this period is too short, the actions may fail. Evaluate the time required for your custom actions and set an appropriate timeout period.
Default Execution Policy
Select Continue.
Send Notification When Lifecycle Hook Takes Effect
Configure the template with the following settings:
Notification Method: Select OOS Template.
OOS Template Type: Select Public Templates.
Public Template: Select ACS-ESS-LifeCycleModifyRedisIPWhitelist.
Configure the execution parameters for
ACS-ESS-LifeCycleModifyRedisIPWhitelistwith the following settings:RedisInstanceId: Enter the ID of your Tair instance.
ModifyIPWhitelistMode: Select
Append, which corresponds to a scale-out and adds the ECS instance to the Tair instance whitelist.RAM role assumed by OOS: Select OOSServiceRole. In the procedure, permissions to manage ECS, Auto Scaling, and Redis resources have been added to the OOSServiceRole RAM role. The OOS service assumes this role to obtain the required permissions.
Trigger a scale-out.
This tutorial shows how to manually execute a scaling rule to trigger a scale-out. You can also use scheduled tasks or event-triggered tasks to trigger a scale-out.
NoteLifecycle hooks take effect only when a scaling rule triggers a scale-out or scale-in. They do not take effect when you manually add or remove existing ECS instances.
Click the Scaling Rules and Event-triggered Tasks tab.
On the Scaling Rules tab, click Create Scaling Rule.
Set the parameters for the scaling rule and click OK.
The following table describes the parameters. Use the default values for the parameters that are not mentioned.
Parameter
Description
Rule Name
Enter
Add1.Rule Type
Select Simple Scaling Rule.
Operation
Set the value to
Add 1 instance.Find the
Add1scaling rule that you created and click Perform in the Actions column.Click OK.
After the scaling rule executes, an ECS instance is automatically created. The
ESSHookForAddRedisWhitelistlifecycle hook then places the instance on hold and notifies the OOS service to execute the operations defined in theACS-ESS-LifeCycleModifyRedisIPWhitelisttemplate.
Step 3: View the Tair instance whitelist
Log on to the console of Tair (Redis OSS-compatible).
In the left-side navigation pane, click Instance List.
Find your Tair instance and click its ID in the Instance ID/Name column.
In the left-side navigation pane, click Whitelist Settings.
If the new ECS instance's private IP address appears on the Tair instance whitelist, the
ACS-ESS-LifeCycleModifyRedisIPWhitelisttemplate has executed successfully.If the ECS instance exists but its private IP address is not on the Tair instance whitelist, check the OOS task's execution status in the OOS console. For details, see (Optional) Step 4: Check the OOS execution.
(Optional) Step 4: Check the OOS execution
Log on to the OOS console.
In the navigation pane on the left, choose .
Find the execution based on the start 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 a task execution.
NoteIf an execution fails, the execution details page displays the error message.
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. |