This topic describes how you can switch the network type of an ApsaraDB RDS instance from a classic network to a virtual private cloud (VPC) by using the ApsaraDB RDS console or by calling the required API operation.

Prerequisites

Before you switch the network type, make sure that the following conditions are met:
  • An Alibaba Cloud account is created. If you do not have an Alibaba Cloud account, create one. For more information, see Create an Alibaba Cloud account.
  • The ApsaraDB RDS instance is deployed in a classic network.
  • VPCs and vSwitches are available in the zone to which the ApsaraDB RDS instance belongs. For more information, see Work with VPCs.

Background information

For more information about how you can switch the network type of an ApsaraDB RDS instance from a classic network to a VPC, see Hybrid access solution for smooth migration from classic networks to VPCs.
Note
  • When you switch the network type, you can specify a retention period for the classic network endpoint. After the retention period expires, the classic network endpoint is automatically deleted. Before the endpoint is deleted, you will receive SMS messages.

  • If the ApsaraDB RDS instance is a subdatabase of a DRDS instance, the DRDS instance will be disconnected from the ApsaraDB RDS instance after the network type is switched. You must manually reconnect both instances.

Switch the network type by using the ApsaraDB RDS console

  1. Log on to the ApsaraDB RDS console.
  2. In the left-side navigation pane, click Instances.
  3. Select the region where the ApsaraDB RDS instance is deployed.
  4. Click the ID of the ApsaraDB RDS instance.
  5. In the left-side navigation pane, click Databases Connection.
  6. On the Instance Connection tab, click Switch to VPC.
  7. In the Switch to VPC dialog box, select the VPC and vSwitch to which you want to switch.
  8. Select Reserve Original Classic Network Endpoint and set Expiration Time for the classic network endpoint.
    • Seven days before the classic network endpoint expires, the system will send SMS messages to the mobile phone associated with your Alibaba Cloud account once a day.
    • When the classic network endpoint expires, it is automatically deleted. You cannot access the database through the classic network endpoint. To ensure that your services are not interrupted, set the retention period as needed. After you configure the hybrid access mode, you can change the expiration time.
  9. Click OK. An original classic endpoint is added in the console.
    Classic network

Modify the retention period of the classic network endpoint by using the console

After you set the retention period of the classic network endpoint, you can change the expiration date in the console to extend the retention period before the endpoint expires.

During the period in which your instance can be connected over the classic network or VPCs, you can specify the expiration date for the endpoint of the classic network. The changes immediately take effect. For example, if the classic network endpoint is set to expire on August 18, 2017 and you extend the expiration date by 14 days on August 15, 2017, the endpoint will be deleted on August 29, 2017.

  1. Log on to the ApsaraDB RDS console.
  2. In the left-side navigation pane, click Instances.
  3. Select the region where the ApsaraDB RDS instance is deployed.
  4. Click the ID of the ApsaraDB RDS instance.
  5. In the left-side navigation pane, click Databases Connection.
  6. On the Instance Connection tab, click Change Expiration Time.
  7. Select the expiration time and click OK.

Switch the network type by calling the relevant API operation

  1. Download relevant SDKs.
  2. Call the ModifyDBInstanceNetworkType operation to switch the network type.
    Request parameters
    Parameter Type Required Description
    Action String Yes The operation that you want to perform. Set the value to ModifyDBInstanceNetworkType.
    DBInstanceId String Yes The ID of the instance.
    InstanceNetworkType String Yes The network type of the instance. Valid values:
    • VPC: the VPC type
    • Classic: the classic network type
    VPCId String No The ID of the VPC.
    VSwitchId String No The ID of the vSwitch. This parameter is required if the VPC ID is specified.
    PrivateIpAddress String No Enter an IP address that belongs to the CIDR block of the vSwitch. If you do not enter an IP address, the system assigns a private IP address based on the VPC ID and the vSwitch ID.
    RetainClassic String No
    Specifies whether to retain the classic network endpoint. Default value: False:
    • True: retains the classic network endpoint.
    • False: does not retain the classic network endpoint.
    ClassicExpiredDays String No

    The retention period of the classic network endpoint. Unit: days. Valid values: 1 to 120. Default value: 7.

    This parameter is required if RetainClassic is set to True.

    Response parameters

    Parameter Type Description
    RequestId String The ID of the request.
    TaskId String The ID of the task.

    Example

    If you want to retain the classic network endpoint:
    • Set the RetainClassic parameter to True. The classic network endpoint can be retained.
    • Set the ClassicExpiredDays parameter for the retention period of a classic network endpoint. After the classic network endpoint expires, the endpoint will be deleted.
    import com.aliyuncs.DefaultAcsClient;
     import com.aliyuncs.IAcsClient;
     import com.aliyuncs.exceptions.ClientException;
     import com.aliyuncs.exceptions.ServerException;
     import com.aliyuncs.profile.DefaultProfile;
     import com.aliyuncs.profile.IClientProfile;
     import com.aliyuncs.rds.model.v20140815.ModifyDBInstanceNetworkTypeRequest;
     import com.aliyuncs.rds.model.v20140815.ModifyDBInstanceNetworkTypeResponse;
     import org.junit.Test;
     public class ModifyDBInstanceNetworkTypeTest {
         @Test
         public  void switchNetwork_success() {
         ModifyDBInstanceNetworkTypeRequest request=new ModifyDBInstanceNetworkTypeRequest ();
             request.setInstanceId("<Your instance ID>");
             request.setInstanceNetworkType ("VPC");
             request.setVpcId("<VpcId: This parameter is required if TargetNetworkType is set to VPC.>");
             request.setVSwitchId("<VSwitchId: This parameter is required if TargetNetworkType is set to VPC>");
             request.setRetainClassic("<Specifies whether to retain the classic network endpoint. The value True specifies to retain the classic network endpoint, while the value False does not.>");
             request.setClassicExpiredDays("The retention period of the classic network endpoint");
             IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<Your AccessKey ID>",
                 "<<Your AccessKey secret>>");
             IAcsClient client = new DefaultAcsClient(profile);
         try {
                 ModifyDBInstanceNetworkTypeResponse response
                     = client.getAcsResponse(request);
                 System.out.println(response.getRequestId());
         }catch (ServerException e) {
                 e.printStackTrace();
         }
             catch (ClientException e) {
                 e.printStackTrace();
             }
         }
     }
  3. Call the DescribeDBInstanceNetInfo API operation to view the classic network endpoint and the VPC endpoint.

    Request parameters

    Parameter Type Required Description
    Action String Yes The operation that you want to perform. Set the value to DescribeDBInstanceNetInfo.
    DBInstanceId String Yes The ID of the instance.
    Response parameters
    Parameter Type Description
    DBInstanceNetInfos List The connection information of the instance.
    InstanceNetworkType String The network type of the instance. Valid values:
    • VPC: the VPC type
    • Classic: the classic network type
    DBInstanceNetInfo
    Parameter Type Description
    ConnectionString String The DNS connection string.
    IPAddress String The IP address.
    IPType String
    The types of IP addresses for instances deployed in classic networks include:
    • Inner: a private IP address
    • Public: a public IP address
    The types of IP addresses for instances deployed in VPCs include:
    • Private: a private IP address
    • Public: a public IP address
    Port String The port information.
    VPCId String The ID of the VPC.
    VSwitchId String The ID of the vSwitch.
    ExpiredTime String The expiration date.
    Example
    import com.aliyuncs.IAcsClient;
     import com.aliyuncs.exceptions.ClientException;
     import com.aliyuncs.exceptions.ServerException;
     import com.aliyuncs.profile.DefaultProfile;
     import com.aliyuncs.profile.IClientProfile;
     import com.aliyuncs.rds.model.v20140815.DescribeDBInstanceNetInfoRequest;
     import import com.aliyuncs.rds.model.v20140815.DescribeDBInstanceNetInfoResponse;
     import org.junit.Test;
     public class DescribeDBInstanceNetInfoTest {
         @Test
         public  void describeDBInstanceNetInfo_success() {
             DescribeDBInstanceNetInfoRequest request=new DescribeDBInstanceNetInfoRequest();
             request.setInstanceId("<Your instance ID>");
             IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<Your AccessKey ID>",
                 "<<Your AccessKey secret >>");
             IAcsClient client = new DefaultAcsClient(profile);
             try {
                 DescribeDBInstanceNetInfoResponse response
                     = client.getAcsResponse(request);
                 System.out.println(response.getRequestId());
         }catch (ServerException e) {
                 e.printStackTrace();
         }
             catch (ClientException e) {
                 e.printStackTrace();
             }
         }
     }

Modify the retention period of the classic network endpoint by using the relevant API operation

  1. Download relevant SDKs.
  2. Call the ModifyDBInstanceNetworkExpireTime operation to modify the retention period of the classic network endpoint.
    Request parameters
    Parameter Type Required Description
    Action String Yes The operation that you want to perform. Set the value to ModifyDBInstanceNetworkExpireTime.
    DBInstanceId String Yes The ID of the instance.
    ConnectionString String Yes The classic network endpoint for which retention period you want to extend. Classic network endpoints are divided into the classic network endpoint of the current instance and the classic network endpoint with read/write splitting.
    ClassicExpiredDays Integer Yes The retention period of the classic network endpoint. Unit: days. Valid values: 1 to 120.
    Response parameters
    Parameter Type Description
    RequestId String The ID of the request.

    Example

    public static void main(String[] args) {
         ModifyDBInstanceNetExpireTimeRequest request = new ModifyDBInstanceNetExpireTimeRequest();
         request.setClassicExpiredDays(3);
         request.setConnectionString("<The connection string>");
         request.setInstanceId("<The instance ID>");
         IClientProfile profile
                 = DefaultProfile.getProfile("cn-qingdao", "<Your AccessKey ID>",
                 "<Your AccessKey secret>");
         IAcsClient client = new DefaultAcsClient(profile);
         try {
             ModifyDBInstanceNetExpireTimeResponse response
                     = client.getAcsResponse(request);
             System.out.println(response.getRequestId());
         }catch (ServerException e) {
             e.printStackTrace();
         }
         catch (ClientException e) {
             e.printStackTrace();
         }
     }