All Products
Search
Document Center

Auto Scaling:Associate instances in a scaling group with cloud databases

Last Updated:Jun 28, 2024

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

  • ApsaraDB RDS

  • PolarDB

  • ApsaraDB for Redis (Redis)

  • ApsaraDB for MongoDB (MongoDB)

Method 2: Associate a scaling group with cloud databases

ECS instances and elastic container instances

  • ApsaraDB RDS

  • Redis

  • MongoDB

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

ECS

  • PolarDB

  • Redis

  • MongoDB

  • AnalyticDB for MySQL

(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.

    Note

    If 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

Configure a security group

Redis

Batch add public and private IP addresses of ECS instances by using security groups

MongoDB

Add a security group

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

  • ApsaraDB RDS

  • Redis

  • MongoDB

If you create a scaling group by calling the CreateScalingGroup operation, you can use the DBInstance.N.Type parameter to specify the type of the desired cloud databases and use the DBInstance.N.DBInstanceId parameter to associate the desired cloud databases with the scaling group. For more information, see CreateScalingGroup.

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

  • ApsaraDB RDS

  • Redis

  • MongoDB

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:

  • If the scaling group contains existing instances, you can configure the ForceAttach parameter to specify whether to add the private IP addresses of the instances to the IP address whitelist of the cloud database that you want to associate with the scaling group.

  • If the desired cloud database does not exist, scaling failures can occur in the scaling group. Auto Scaling automatically scans the associated cloud databases. If Auto Scaling detects one of the cloud databases is missing, the association between the cloud database and the scaling group automatically becomes invalid.

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: