Can Applications Deployed in a VPC Call APIs?

Yes, applications deployed in a VPC can call APIs by default. If domain name resolution fails, configure a DNS server on the current endpoint by following the instructions in Configuring an Intranet DNS Server. After the configuration, applications deployed in the VPC can call APIs.

Configuring an Intranet DNS Server

To configure a DNS server, specify its IP address in the /etc/resolv.conf file.

The IP address of the intranet DNS server depends on which region you are located in. Find the IP address of the intranet DNS server in your region from the private DNS server addresses mentioned in the Domain Name Service FAQs.

Add an intranet DNS server with either of the following two methods:

  • Method 1: Modify the subnet information of the VPC.

  • Method 2: Edit the /etc/resolv.conf file.

    Note

    The intranet DNS server configurations become invalid after the ECS restarts, and the intranet DNS server must be configured again. Therefore, method 1 is recommended.

Method 1

Perform the following procedure to add a DNS server IP address to the subnet configurations of the ECS in the VPC.

  1. Log in to the management console.

  2. Click image1 in the upper left corner to select a region.

  3. In the service list, choose Compute > Elastic Cloud Server.

  4. Click the name of the ECS you want to use.

  5. On the ECS details page, view the NIC information, and click image2 to view the subnet name of the ECS.

  6. On the ECS basic information page, view the VPC name of the ECS.

  7. Click the VPC name to visit the VPC console.

  8. Choose Subnets in the left navigation pane.

  9. Locate the subnet mentioned in 5 and click the subnet name.

  10. Change the DNS server address of the subnet and click OK.

    For example, change the address to 100.125.1.250.

  11. Restart the ECS. Check that the /etc/resolv.conf file contains the IP address of the DNS server to be configured, and the IP address is less than those of all other DNS servers.

    The following figure shows the IP address 100.125.1.250 of the DNS server to be configured.

    image3

    Note

    Modifying the subnet information of a VPC will affect all ECSs created using the subnet.

Method 2

Add the IP address of the intranet DNS server to the /etc/resolv.conf file.

For example, if you are located in region01, add an intranet DNS server of IP address 100.125.1.250 to the /etc/resolv.conf file.

Note

  • The IP address of the new DNS server must be less than those of all other DNS servers.

  • The DNS configurations take effect immediately after the /etc/resolv.conf file is saved.