Overview of best practices for lifecycle hooks and OOS templates

更新时间:
复制 MD 格式

Lifecycle hooks pause scaling activities and hand control to CloudOps Orchestration Service (OOS), which runs the operations and maintenance (O&M) tasks defined in an OOS template before the activity resumes. Use this pattern to automate instance preparation during scale-out events (for example, binding secondary Elastic Network Interfaces (ENIs) or updating database whitelists) and instance cleanup during scale-in events (for example, copying logs or clearing data).

How it works

When a scaling activity is triggered, Auto Scaling suspends the activity and puts the affected ECS instances into the Pending:Wait state. OOS then runs the O&M operations specified in the template. After OOS finishes, the instances leave Pending:Wait and the scaling activity either continues or ends based on the result.

Integrated usage

The outcome depends on whether the O&M operations succeed:

If the operations succeed, the scaling activity continues:

  • Scale-out: ECS instances are added to the scaling group.

  • Scale-in: ECS instances are removed from the scaling group.

If the operations fail, the scaling activity ends:

  • Scale-out: ECS instances are released.

  • Scale-in: ECS instances are still removed from the scaling group. The scale-in event is not affected by the failure.

Important

A failed O&M operation does not protect instances from scale-in. If the goal is to preserve data before termination, ensure the OOS template handles data preservation tasks.

Why use OOS templates

OOS templates offer several advantages over custom notification handlers:

  • Composable O&M workflows: Templates define task sequences, execution order, and input/output parameters, making it straightforward to implement multi-step O&M processes.

  • Automatic triggering: Lifecycle hook notifications invoke OOS directly — no custom code needed to parse notification payloads.

  • Ready-to-use public templates: Alibaba Cloud provides public templates for common tasks. See .

  • Custom templates: Build your own templates for scenarios not covered by public templates. See .

For more information about OOS, see .

Available public templates

The following public templates cover the most common O&M tasks for lifecycle hooks. Each template name maps directly to the OOS public template catalog.

TemplateApplicable eventDescriptionGuide
ACS-ESS-LifeCycleApplyAutoSnapshotPolicyScale-outApply automatic snapshot policies to disks.Apply an automatic snapshot policy to ECS instances
ACS-ESS-LifeCycleRunCommandScale-out and scale-inRun commands on ECS instances.Automatically execute scripts on ECS instances
ACS-ESS-LifeCycleModifyPolarDBIPWhitelistScale-out and scale-inUpdate the IP address whitelist of PolarDB clusters.Automatically add or remove ECS instance IP addresses from a PolarDB cluster whitelist
ACS-ESS-LifeCycleModifyRedisIPWhitelistScale-out and scale-inUpdate the IP address whitelist of ApsaraDB for Redis instances.Automatically add or remove ECS instance IP addresses from an ApsaraDB for Redis whitelist
ACS-ESS-LifeCycleModifyMongoDBIPWhitelistScale-out and scale-inUpdate the IP address whitelist of ApsaraDB for MongoDB instances.Automatically add or remove ECS instance IP addresses from a MongoDB instance whitelist
ACS-ESS-LifeCycleModifyAnalyticDBIPWhitelistScale-out and scale-inUpdate the IP address whitelist of AnalyticDB for MySQL clusters.Automatically add or remove ECS instance IP addresses from an AnalyticDB for MySQL cluster whitelist
ACS-ESS-LifeCycleAttachNASFileSystemToInstanceScale-outMount NAS file systems to ECS instances.Mount NAS file systems to ECS instances
ACS-ESS-LifeCycleCreateNetworkInterfaceAndEipAndAttachToInstanceScale-outCreate secondary ENIs and Elastic IP Addresses (EIPs), associate each EIP with a secondary ENI, and bind the ENIs to ECS instances.Automatically bind secondary ENIs to ECS instances
ACS-ESS-LifeCycleDetachNetworkInterfaceAndDeleteEipScale-inUnbind secondary ENIs from ECS instances, then release the ENIs and their associated EIPs.Automatically unbind secondary ENIs from ECS instances
ACS-ESS-LifeCycleAllocateEipAddressAndAttachToInstanceScale-outCreate EIPs and associate them with ECS instances.Automatically associate EIPs with ECS instances
ACS-ESS-LifeCycleReleaseEipAddressFromInstanceScale-inDisassociate EIPs from ECS instances and release them.Enable the automatic release feature for an EIP

What's next

  • Learn about ECS instance state transitions during scaling activities: Instance lifecycles

  • Browse all OOS public templates:

  • Build a template for your own requirements: