If an Elastic Compute Service (ECS) instance and an ApsaraDB for MongoDB instance do not belong to the same Alibaba Cloud account, you can use the methods in this topic to connect the ECS instance to the ApsaraDB for MongoDB instance over an internal network.

Method 1: Migrate the ApsaraDB for MongoDB instance to the Alibaba Cloud account to which the ECS instance belongs

This method uses the data migration feature of Data Transmission Service (DTS) to migrate the ApsaraDB for MongoDB instance to the Alibaba Cloud account to which the ECS instance belongs. For more information about DTS, see What is DTS?

Procedure

  1. Create an ApsaraDB for MongoDB instance that has the same region, zone, and virtual private cloud (VPC) as the ECS instance within the Alibaba Cloud account to which the ECS instance belongs. For more information about how to create an ApsaraDB for MongoDB instance, see the following topics.
    Note If you have created such an ApsaraDB for MongoDB instance, skip this step.
  2. Migrate data from the source ApsaraDB for MongoDB instance to the ApsaraDB for MongoDB instance that belongs to the same account as the ECS instance. For more information, see Migrate data between ApsaraDB for MongoDB instances of different Alibaba Cloud accounts.
  3. Add the private IP address of the ECS instance to a whitelist of the ApsaraDB for MongoDB instance. For more information, see Configure a whitelist for an ApsaraDB for MongoDB instance.
    Note For information about how to obtain the IP address of an ECS instance, see View instance information.

Method 2: Migrate the ECS instance to the Alibaba Cloud account to which the ApsaraDB for MongoDB instance belongs

This method migrates the ECS instance to the Alibaba Cloud account to which the ApsaraDB for MongoDB instance belongs by sharing the ECS instance as a custom image.

Prerequisites

The ECS instance and the ApsaraDB for MongoDB instance are in the same region. Images cannot be shared across regions.

Procedure

  1. Create a custom image from an ECS instance. For more information, see Create a custom image from an instance.
  2. Share the custom image to the Alibaba Cloud account to which the ApsaraDB for MongoDB instance belongs. For more information, see Procedure.
  3. Create an ECS instance from the custom image. For more information, see Create an ECS instance by using a custom image.
    Note When you create the ECS instance, select the same VPC as the ApsaraDB for MongoDB instance.
  4. Add the private IP address of the ECS instance to a whitelist of the ApsaraDB for MongoDB instance. For more information, see Configure a whitelist for an ApsaraDB for MongoDB instance.
    Note For information about how to obtain the IP address of an ECS instance, see View instance information.

Method 3: Establish a connection between the ECS instance and the ApsaraDB for MongoDB instance by using CEN

This method uses Cloud Enterprise Network (CEN) to establish a connection between the VPCs that belong to different Alibaba Cloud accounts to connect the ECS instance to the ApsaraDB for MongoDB instance. For more information about CEN, see What is CEN?
Note Make sure that the CIDR blocks of the involved VPCs or vSwitches do not conflict with each other.

Procedure

  1. Switch the network type of the ApsaraDB for MongoDB instance to VPC. For more information, see Switch the network type of an ApsaraDB for MongoDB instance from classic network to VPC. If the network type is VPC, skip this step.
  2. Migrate the ECS instance from the classic network to a VPC. For more information, see Migrate ECS instances from a classic network to a VPC. If the network type is VPC, skip this step.
  3. Based on the running environment, select one of the following CEN-based connections over an internal network. For more information, see the following topics:
  4. Add the private IP address of the ECS instance to a whitelist of the ApsaraDB for MongoDB instance. For more information, see Configure a whitelist for an ApsaraDB for MongoDB instance.
    Note For information about how to obtain the IP address of an ECS instance, see View instance information.