This topic describes how to use a lifecycle hook of Auto Scaling to put ECS instances into the Pending Add or Pending Remove state and then use an Operation Orchestration Service (OOS) template to automatically mount Apsara File Storage NAS (NAS) file systems to Linux ECS instances.
Prerequisites
- An Alibaba Cloud account is created. To create an Alibaba Cloud account, go to the account registration page.
- A scaling group is created and enabled.
- A NAS file system is created, and a mount target is created for the NAS file system. For information about mount targets, see Manage mount targets. Make sure that the following requirements are met:
- If the network type of the scaling group is virtual private cloud (VPC), the network type of the mount target must also be VPC. The mount target and the scaling group must reside in the same VPC.
- If the network type of the scaling group is classic network, the network type of the mount target must also be classic network.
- The type of protocol that you want to use to mount NAS file systems must be Network File System (NFS).
- A RAM role is created for Operation Orchestration Service (OOS). The trusted entity type of the RAM role is Alibaba Cloud Service. The trusted service is Operation Orchestration Service. The RAM role has the permissions that are required to perform operations on the OOS template. For more information, see Grant RAM permissions to OOS. Note In this topic, the OOSServiceRole RAM role is used as an example. You can also use other roles.
Background information
A file system is the basic storage unit of NAS. After you mount NAS file systems to ECS instances, you can use the NAS file systems in a similar way as you use local file systems. This enhances data security and fault tolerance. You cannot specify NAS file systems when you create a scaling configuration. However, you can use a lifecycle hook and an OOS template to automatically mount NAS file systems to ECS instances. This is more efficient than manually mounting file systems to ECS instances after the instances are created.
Procedure
Step 1: Grant OOS permissions to a RAM user
If you want to execute OOS templates as a RAM user, you must have OOS permissions. When you execute the ACS-ESS-LifeCycleAttachNASFileSystemToInstance public template, you also need to use ECS resources, Auto Scaling resources, and NAS file systems.
- Log on to the RAM console.
- Create a policy.
- Attach the policy to the OOSServiceRole RAM role.
Step 2: Create a lifecycle hook and trigger a scale-out activity
- Log on to the Auto Scaling console.
- In the left-side navigation pane, click Scaling Groups.
- In the top navigation bar, select the region where Auto Scaling is activated.
- Find a scaling group and use one of the following methods to go to the scaling group details page:
- Click the ID of the scaling group in the Scaling Group Name/ID column.
- Click Details in the Actions column.
- Create a lifecycle hook.
- Trigger a scale-out activity.A scale-out activity is triggered in this example by manually executing a scaling rule. You can also trigger scale-out activities by using scheduled or event-triggered tasks.Note If 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.After the scaling rule is executed, an ECS instance is automatically created. The ESSHookForAttachNAS lifecycle hook in the scaling group puts the ECS instance into the Pending Add state. Auto Scaling notifies OOS to perform the O&M operations specified in the ACS-ESS-LifeCycleAttachNASFileSystemToInstance public template on the ECS instance.
- Check whether the ECS instance meets your expectations.
Step 3: (Optional) View the execution status of the OOS template
- Log on to the OOS console.
- In the left-side navigation pane, click Executions.
- Find the execution task by time and click Details in the Actions column.
- In the upper part of the page, click Advanced View and view the execution status on the Execution Result tab.
- If the execution is successful, the execution status appears on the Execution Result tab.
- If the execution fails, an error message appears on the Execution Result tab.
- If the execution is successful, the execution status appears on the Execution Result tab.
FAQ
- Error message: Forbidden.Unauthorized message: A required authorization for the specified action is not supplied.
Solution: Check whether the required permissions, such as the sample permissions in Step 1, are granted to the RAM role OOSServiceRole. Before OOS can manage the resources that are described in the OOS template, you must grant the required permissions to the RAM role.
- Error message: Forbidden.RAM message: User not authorized to operate on the specified resource, or this API doesn't support RAM.
Solution: Check whether the required permissions, such as the sample permissions in Step 1, are granted to the RAM role OOSServiceRole. Before OOS can manage the resources that are described in the OOS template, you must grant the required permissions to the RAM role.
- Error message: LifecycleHookIdAndLifecycleActionToken.Invalid message: The specified lifecycleActionToken and lifecycleActionId you provided does not match any in process lifecycle action.
Solution: Estimate the timeout period of the lifecycle hook to make sure that the O&M task specified in the OOS template can be completed within the timeout period.