If an Elastic Compute Service (ECS) instance in a virtual private cloud (VPC) cannot access the Internet, you cannot call API operations on the ECS instance. This topic describes how to call API operations over a VPC by modifying the endpoint field.

Background

VPC endpoints use public service addresses. If the ECS instance in your VPC cannot access the Internet, you cannot call API operations by using Alibaba Cloud CLI or SDKs. For more information about VPC endpoints, see Request syntax.

You can modify the endpoint field to call API operations over a VPC. Make sure that you use a supported endpoint.
Note
  • To call API operations over a VPC, the region of the VPC-connected ECS instance must be the same as that of the endpoint. Cross-region operations are not supported.
  • For more information about the endpoints, see Regions.

Call an operation over a VPC by using Alibaba Cloud CLI

To call an operation over a VPC by using Alibaba Cloud CLI, set the Endpoint field to the corresponding endpoint of a specific region. Example:
aliyun vpc DescribeRegions --endpoint vpc-vpc.cn-hangzhou.aliyuncs.com

Call an operation over a VPC by using Alibaba Cloud SDKs

To call an operation over a VPC by using Alibaba Cloud SDKs, set the Endpoint field to the corresponding endpoint of a specific region. Example in Java:

DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<AccessKeyId>", "<AccessKeySecret>");
IAcsClient client = new DefaultAcsClient(profile);

// The configuration takes effect globally. where:
// <product> specifies the service name and Vpc is used in this example. <Endpoint> specifies the endpoint of the specific region.
DefaultProfile.addEndpoint("cn-hangzhou", "vpc", "vpc-vpc.cn-hangzhou.aliyuncs.com");

// The configuration takes effect only for this request. For example, when you call the DescribeRegions operation:
DescribeRegionsRequest regionsRequest = new DescribeRegionsRequest();
// If you set productNetwork, you do not need to set SysEndpoint.
regionsRequest.setSysEndpoint("<Endpoint>");
// Configure the network. Valid values of productNetwork: vpc and public.
// Set the parameter to vpc when you call the operation over a VPC. Set the parameter to public when you call the operation over the Internet. Default value: public.
regionsRequest.productNetwork = "vpc";
DescribeRegionsResponse regionsResponse = client.getAcsResponse(regionsRequest);