Call API operations over an Alibaba Cloud VPC

更新时间:
复制 MD 格式

If your scaling group contains Elastic Compute Service (ECS) instances that reside in a virtual private cloud (VPC) and cannot access the Internet, you can configure Alibaba Cloud DNS PrivateZone to enable API calling over the VPC for the instances.

Background information

Auto Scaling provides public network endpoints. If your scaling group contains ECS instances to which no public bandwidth or public IP addresses are allocated, API requests initiated by using Alibaba Cloud CLI or SDKs are not supported. In this case, you can associate Alibaba Cloud DNS PrivateZone with the VPC in which the ECS instances of your scaling group reside to implement API calling over the VPC. Alibaba Cloud DNS PrivateZone and the ECS instances must reside in the same region.

  • This solution is applicable to only ECS instances that reside in VPCs. You cannot apply this solution if Alibaba Cloud DNS PrivateZone and your ECS instances are in different regions.

  • We recommend that you specify an image that has available Alibaba Cloud CLI or SDKs in your scaling configuration. This ensures that the required dependencies can be downloaded to the ECS instances that are created from the scaling configuration, even if the ECS instances cannot access the Internet.

  • The following table describes the endpoints that support Alibaba Cloud DNS PrivateZone. Make sure that your endpoint is listed in the table.

    Alibaba Cloud region

    Region ID

    CNAME record

    Public endpoint

    China (Beijing)

    cn-beijing

    popunify-vpc.cn-beijing.aliyuncs.com

    ess.aliyuncs.com

    China (Hangzhou)

    cn-hangzhou

    popunify-vpc.cn-hangzhou.aliyuncs.com

    ess.aliyuncs.com

    China (Shanghai)

    cn-shanghai

    popunify-vpc.cn-shanghai.aliyuncs.com

    ess.aliyuncs.com

    China (Shenzhen)

    cn-shenzhen

    popunify-vpc.cn-shenzhen.aliyuncs.com

    ess.aliyuncs.com

    China (Hong Kong)

    cn-hongkong

    popunify-vpc.cn-hongkong.aliyuncs.com

    ess.aliyuncs.com

    Singapore

    ap-southeast-1

    popunify-vpc.ap-southeast-1.aliyuncs.com

    ess.aliyuncs.com

Procedure

  1. Log on to the Alibaba Could DNS console.

  2. In the left-side navigation pane, click PrivateZone.

  3. In the upper-right corner, click Manage Configuration Mode.

  4. On the User Domain tab, click Add Zone.

  5. In the Add Built-in Authoritative Zone panel, configure the following parameters and click OK.

    • Built-in Authoritative Zone: Enter an Auto Scaling endpoint that supports Alibaba Cloud DNS PrivateZone, such as ess.cn-hangzhou.aliyuncs.com.

    • Subdomain Recursive Resolution Proxy: If you enable this option, DNS queries for subdomains that are not configured in the zone file are forwarded to public authoritative DNS servers for resolution.

      The name that you enter for the Built-in Authoritative Zone cannot be changed after creation. For Zone Type, select either Built-in Authoritative Acceleration Zone for the lowest latency or Built-in Authoritative Standard Zone for cached responses. Configure the Effective Scope as needed.

  6. Find the PrivateZone that you created. In the Actions column, click Resource Record Settings.

  7. On the Resource Record Settings tab, click Add Record.

  8. In the Add Record panel, configure the following parameters and click OK.

    • Record Type: Select CNAME.

    • Hostname: Enter @. This resolves the zone name itself (for example, ess.cn-hangzhou.aliyuncs.com).

    • Record Value: Enter the CNAME record value for the corresponding region, as listed in the table in the "Background information" section.

    • TTL: The time to live. In this example, select 1 Minute.

  9. Return to the PrivateZone list. Find the PrivateZone that you created and click Effective Scope Settings in the Actions column.

  10. Select the same region as the PrivateZone. Select the VPC to associate (the Alibaba Cloud VPC internal network), and then click OK.

    For more information, see Associate a zone with VPCs across accounts.

    Note

    The Alibaba Cloud VPC must be the VPC in which the ECS instances of your scaling group reside.

Result

After you associate the created zone with the VPC in which the ECS instances of your scaling group reside, you can remotely log on to one of the ECS instances and test whether you can access the endpoint of the desired region from the ECS instance. For more information, see Connect using VNC.

In this example, the ess.cn-hangzhou.aliyuncs.com endpoint is used to test the access.

  • Run the ping command to test whether data packets can be sent or received over the VPC.

    ping ess.cn-hangzhou.aliyuncs.com
    [root@xxx          ~]# ping ess.cn-hangzhou.aliyuncs.com
    PING popunify-vpc-cn-hangzhou.aliyuncs.com.gds.alibadns.com (xxx) 56(84) bytes of data.
    64 bytes from xxx: icmp_seq=1 ttl=102 time=1.30 ms
    64 bytes from xxx: icmp_seq=2 ttl=102 time=1.34 ms
    64 bytes from xxx: icmp_seq=3 ttl=102 time=1.31 ms
    64 bytes from xxx: icmp_seq=4 ttl=102 time=1.33 ms
    64 bytes from xxx: icmp_seq=5 ttl=102 time=2.29 ms
    64 bytes from xxx: icmp_seq=6 ttl=102 time=1.30 ms
    64 bytes from xxx: icmp_seq=7 ttl=102 time=2.99 ms
    ^C
    --- popunify-vpc-cn-hangzhou.aliyuncs.com.gds.alibadns.com ping statistics ---
    7 packets transmitted, 7 received, 0% packet loss, time 6009ms
    rtt min/avg/max/mdev = 1.308/1.698/2.990/0.626 ms
  • Use Alibaba Cloud CLI to call the DescribeRegions operation and specify the access endpoint by using the --endpoint field.

    aliyun ess DescribeRegions --endpoint ess.cn-hangzhou.aliyuncs.com
    [root@                    'l]# aliyun ess DescribeRegions --endpoint ess.cn-hangzhou.aliyuncs.com
    {"RequestId":"1339AEF0-B414-4E06-B9B9-604B9E551BC2","Regions":{"Region":[{"ClassicUnavailable":false,"RegionId":"cn-hangzhou-tes
    x xxx","RegionEndpoint":"ess.aliyuncs.com","LocalName":"x x xxx","VpcUnavailable":false},{"ClassicUnavailable":false,"RegionId"
    :"cn-hangzhou-tes xxx","RegionEndpoint":"ess.aliyuncs.com","LocalName":"x x 2x","VpcUnavailable":false},{"ClassicUnavailable":
    false,"RegionId":"cn-hangzhou-test-300","RegionEndpoint":"ess.aliyuncs.com","LocalName":"x x 3x","VpcUnavailable":false},{"Clas
    sicUnavailable":false,"RegionId":"cn-qingdao","RegionEndpoint":"ess.aliyuncs.com","LocalName":"x x 1x","VpcUnavailable":false},{
    "ClassicUnavailable":false,"RegionId":"cn-beijing","RegionEndpoint":"ess.aliyuncs.com","LocalName":"x x 2","VpcUnavailable":fal
    se},{"ClassicUnavailable":false,"RegionId":"cn-zhangjiakou","RegionEndpoint":"ess.cn-zhangjiakou.aliyuncs.com","LocalName":"x x
    x3","VpcUnavailable":false},{"ClassicUnavailable":false,"RegionId":"cn-huhehaote","RegionEndpoint":"ess.cn-huhehaote.aliyuncs.co
    m","LocalName":"x x 5","VpcUnavailable":false},{"ClassicUnavailable":false,"RegionId":"cn-hangzhou","RegionEndpoint":"ess.aliyuncs.com","LocalName":"xx","VpcUnavailable":false}]}}