This topic describes how to associate ECS instances in a scaling group with ApsaraDB instances. You can add the ECS instances and the ApsaraDB instances to the same security group, associate the scaling group with the ApsaraDB instances, and add the ECS instances to the whitelists of the ApsaraDB instances.

Background information

ECS instances in a scaling group may be automatically released. Therefore, we recommend that you save your application data to ApsaraDB instances. The console is used in this example to demonstrate how to associate ECS instances in a scaling group with ApsaraDB instances.

Method 1: (Recommended) Add an ECS instance and an ApsaraDB instance to the same security group

When a scaling group and an ApsaraDB instance are of the VPC type and added to the same security group, ECS instances in the scaling group can directly access the ApsaraDB instance.

Note This method applies to all ApsaraDB services such as ApsaraDB RDS and ApsaraDB for MongoDB.

In this example, ApsaraDB RDS for MySQL is used. You can perform the following operations:

Method 2: Associate a scaling group with an ApsaraDB instance

When you create or modify a scaling group, you can associate it with an ApsaraDB RDS instance. After the scaling group is associated with an ApsaraDB RDS instance, all ECS instances in the scaling group can directly access the ApsaraDB RDS instance, regardless of the network type of the scaling group and the ApsaraDB RDS instance.

Note This method applies only to ApsaraDB RDS.
  • Create a scaling group. For more information, see Create a scaling group.
  • Modify the scaling group. For more information, see Modify a scaling group.
    Note If ECS instances exist in a scaling group, you can use the following method to add the instances to the whitelists of the associated ApsaraDB RDS instances when you modify the scaling group:
    • Console: In the Edit Scaling Group dialog box, select Add or remove instances in the scaling group to or from whitelists of RDS instances when you associate or disassociate RDS instances.
    • AttachDBInstances: Set ForceAttach to true.

Method 3: Use lifecycle hooks and OOS templates to add ECS instances to the whitelists of ApsaraDB instances

You can use lifecycle hooks in conjunction with Operation Orchestration Service (OOS) templates to put ECS instances in a scaling group into the wait state. Then, you can add the ECS instances to the whitelists of ApsaraDB instances associated with the scaling group. After the ECS instances are added to the whitelists of the ApsaraDB instances, the ECS instances can directly access the ApsaraDB instances, regardless of the network type of the scaling group and the ApsaraDB instances.

Note This method applies only to PolarDB, ApsaraDB for MongoDB, AnalyticDB for PostgreSQL, and AnalyticDB for MySQL.