Elastic Compute Service (ECS) instances or elastic container instances in a scaling group can be released at any time. In this case, we recommend that you store instance data on cloud databases to ensure persistent storage. This topic describes how to associate instances in a scaling group with cloud databases by adding the private IP addresses of the instances to the IP address whitelists of the cloud databases. This way, the instances can access the cloud databases.
Association methods
Method | Supported instance | Supported cloud database |
(Recommended) Method 1: Add instances and cloud databases to the same security group | ECS instances and elastic container instances |
|
ECS instances and elastic container instances |
| |
ECS |
|
(Recommended) Method 1: Add instances and cloud databases to the same security group
After you configure a security group for a cloud database, the private IP addresses of the ECS instances or elastic container instances in the security group are automatically added to the IP address whitelist of the cloud database. This ensures direct access from the ECS instances or elastic container instances to the cloud database.
Configure a security group for instances in a scaling group
The security group of instances in a scaling group is determined by the scaling configuration from which the instances are created. When you create or modify a scaling configuration, you can configure a security group. For more information, see Create a scaling configuration of the ECS type and Create a scaling configuration of the Elastic Container Instance type.
NoteIf you specify a launch template as the instance configuration source, change the security group configured in the launch template from which instances are created.
For an existing ECS instance, you can go to the Security Groups tab on the instance details page to change the security group. For an existing elastic container instance, you cannot manually change the security group. You must recreate an elastic container instance and configure the desired security group for the instance.
Configure a security group for a cloud database
You must configure the security group of instances for the cloud database that you want to use.
Cloud database | References |
ApsaraDB RDS | Configure a security group for an ApsaraDB RDS for MySQL instance |
PolarDB | |
Redis | Batch add public and private IP addresses of ECS instances by using security groups |
MongoDB |
Method 2: Associate a scaling group with cloud databases
After you associate a scaling group with a cloud database, the private IP addresses of the ECS instances or elastic container instances in the scaling group are automatically added to the IP address whitelist of the cloud database. This ensures direct access from the ECS instances or elastic container instances to the cloud database.
Scenario | Method | Supported cloud database | Description |
New scaling groups | Console | ApsaraDB RDS | If you create a scaling group in the Auto Scaling console, you can configure the Associate ApsaraDB RDS instance parameter to associate one or more ApsaraDB RDS instances with the scaling group. For more information, see Manage scaling groups. |
API |
| If you create a scaling group by calling the CreateScalingGroup operation, you can use the | |
Existing scaling groups | Console | ApsaraDB RDS | If you modify a scaling group in the Auto Scaling console, you can reconfigure the Associate ApsaraDB RDS Instance parameter to specify one or more ApsaraDB RDS instances that you want to associate with the scaling group. For more information, see Manage scaling groups. If the scaling group contains existing instances, you can select When you associate RDS instances with or disassociate RDS instances from the scaling group, existing ECS instances in the scaling group are added to or removed from the whitelists of the RDS instances based on your business requirements. |
API |
| You cannot call the ModifyScalingGroup operation to change the cloud database associated with a scaling group. You can call the ModifyScalingGroup operation to associate the desired cloud databases with a scaling group. You can call the DetachDBInstances operation to disassociate cloud databases that are no longer required from a scaling group. Take note of the following items:
For more information, see AttachDBInstances and DetachDBInstances. |
Method 3: Combine the lifecycle hook feature and an OOS template to add the private IP addresses of scaled-out instances to the IP address whitelists of cloud databases
You can trigger a lifecycle hook to put the ECS instances in a scaling group into a Pending state. Then, Auto Scaling automatically executes the predefined CloudOps Orchestration Service (OOS) template to add the private IP addresses of the scaled-out ECS instances to the IP address whitelist of the desired cloud database. This ensures direct access from the ECS instances or elastic container instances to the cloud database. For more information, see the following topics: