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 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. To create an Alibaba Cloud account, go to the Alibaba Cloud official website. For more information, seeCreate an Alibaba Cloud account.
  • The network type of the RDS instance is the classic network.
  • VPCs and VSwitches are available in the zone to which the RDS instance belongs. For more information, see Create a VPC.

Background information

For more information about how you can switch the network type of an 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 RDS instance is a subdatabase of a DRDS instance, the DRDS instance will be disconnected from the RDS instance after the network type is switched. You must manually reconnect both instances.

Switch the network type by using the RDS console

  1. Log on to the ApsaraDB for RDS console.
  2. On the top of the page, select the region where the RDS instance is deployed.
  3. Click the ID of the RDS instance.
  4. In the left-side navigation pane, click Databases Connection.
  5. On the Instance Connection tab, click Switch to VPC.
  6. On the Switch to VPC page, select the VPC and VSwitch that you want to switch.
  7. 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 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 avoid service disruptions, set the retention period based on your specific needs. After you configure the hybrid access mode, you can change the expiration time.
  8. Click OK. An original classic endpoint is added in the console.

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

After you set the retention period for the classic network endpoint, you can extend the retention period by using the console before the endpoint expires.

During the hybrid access period, you can modify the retention period of the classic network endpoint at any time. The expiration date is timed from the date when you modify the retention period. For example, if the classic network endpoint is set to expire on August 18, 2017 and you modify the expiration date to 14 days later on August 15, 2017, the endpoint will be deleted on August 29, 2017.

  1. Log on to the ApsaraDB for RDS console.
  2. In the top menu bar, select the region where the RDS instance is deployed.
  3. Click the ID of the RDS instance.
  4. In the left-side navigation pane, click Databases Connection.
  5. On the Instance Connection tab, click Change Expiration Time.
  6. 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 an instance.
    InstanceNetworkType String Yes The network type of the instance. Valid values:
    • VPC: a VPC network.

    • Classic: a classic network

    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 An IP address in the CIDR block of the VSwitch. If no IP address is entered, 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: The classic network endpoint is retained.
    • False: The classic network endpoint is not retained.
    ClassicExpiredDays String No

    The retention period of the classic network endpoint in days. The shortest period is 1 day. The longest period is 180 days. The default period is 7 days.

    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.

    Examples

    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 when the TargetNetworkType is set to VPC.>");
             request.setVSwitchId("<VSwitchId: This parameter is required when the TargetNetworkType is set to VPC.>");
             request.setRetainClassic("<Specifies whether to retain the classic network endpoint: Set the value to True to retain and set the value to False not to retain.>");
             request.setClassicExpiredDays("set the retention period of the classic network endpoint");
             IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<Your AccessKey information>",
                 "<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 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 an instance.
    Response parameters
    Parameter Type Description
    DBInstanceNetInfos List The connection information of the instance.
    InstanceNetworkType String The network connection type of the instance. Valid values:
    • VPC: a VPC network.

    • Classic: a classic network

    DBInstanceNetInfo
    Parameter Type Description
    ConnectionString String The connection string of DNS.
    IPAddress String The IP address.
    IPType String

    The IP address type of the classic-network instance: Inner and Public.

    The IP address type of the VPC instance: Private and Public.

    Port String The port information.
    VPCId String The ID of the VPC.
    VSwitchId String The ID of a VSwitch.
    ExpiredTime String The expiration time.
    Examples
    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 information>",
                 "<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 an 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. Value range: 1 to 120 days.
    Response parameters
    Parameter Type Description
    RequestId String The ID of the request.

    Examples

    public static void main(String[] args) {
         ModifyDBInstanceNetExpireTimeRequest request = new ModifyDBInstanceNetExpireTimeRequest();
         request.setClassicExpiredDays(3);
         request.setConnectionString("<Connection string>");
         request.setInstanceId("<Instance ID>");
         IClientProfile profile
                 = DefaultProfile.getProfile("cn-qingdao", "<Your AccessKey information>",
                 "<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();
         }
     }