Help Center/ API Gateway/ FAQs/ API Calling/ Can Applications Deployed in a VPC Call APIs?
Updated on 2024-03-29 GMT+08:00

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 private DNS server addresses.

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.

    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. Click in the upper left corner to select a region.
  2. In the service list, choose Compute > Elastic Cloud Server.
  3. Click the name of the ECS you want to use.
  4. On the ECS details page, view the NIC information, and click to view the subnet name of the ECS.
  5. On the ECS basic information page, view the VPC name of the ECS.
  6. Click the VPC name to visit the VPC console.
  7. Choose Subnets in the left navigation pane.
  8. Locate the subnet mentioned in 4 and click the subnet name.
  9. Change the DNS server address of the subnet and click OK.

    For example, change the address to 100.125.1.250.

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

    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 CN-Hong Kong, add an intranet DNS server of IP address 100.125.1.250 to the /etc/resolv.conf file.

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