处于专有网络VPC下的ECI实例如果没有设置公网IP,则无法直接调用API。本文介绍ECI实例如何通过阿里云内网调用API。

背景信息

由于弹性容器实例提供的默认接入地址(Endpoint)为公网服务地址,当您的ECI实例没有公网IP地址或者没有分配公网带宽时,无法使用阿里云CLI或者SDK等工具发起API请求。此时,您可以配置SDK的内网接入地址(Endpoint),实现通过阿里云内网调用API。相关使用说明如下:
  • 支持的SDK核心库为4.5.3版本及以上。
  • 仅适用于ECI实例所在的地域,即仅能使用对应地域的接入地址操作同地域资源,不支持跨地域操作。

配置SDK内网调用API

SDK支持内网调用API的接入地址(Endpoint)如下表所示,请确保您使用的Endpoint在列举范围内。

地域 地域ID 内网接入地址(Endpoint)
华东 1(杭州) cn-hangzhou eci-vpc.cn-hangzhou.aliyuncs.com
华东 2(上海) cn-shanghai eci-vpc.cn-shanghai.aliyuncs.com
华北 1(青岛) cn-qingdao eci-vpc.cn-qingdao.aliyuncs.com
华北 2(北京) cn-beijing eci-vpc.cn-beijing.aliyuncs.com
华北 3(张家口) cn-zhangjiakou eci-vpc.cn-zhangjiakou.aliyuncs.com
华北 5(呼和浩特) cn-huhehaote eci-vpc.cn-huhehaote.aliyuncs.com
华南 1(深圳) cn-shenzhen eci-vpc.cn-shenzhen.aliyuncs.com
华南2(河源) cn-heyuan eci-vpc.cn-heyuan.aliyuncs.com
华南3(广州) cn-guangzhou eci-vpc.cn-guangzhou.aliyuncs.com
西南 1(成都) cn-chengdu eci-vpc.cn-chengdu.aliyuncs.com
中国(香港) cn-hongkong eci-vpc.cn-hongkong.aliyuncs.com
新加坡 ap-southeast-1 eci-vpc.ap-southeast-1.aliyuncs.com
澳大利亚(悉尼) ap-southeast-2 eci-vpc.ap-southeast-2.aliyuncs.com
马来西亚(吉隆坡) ap-southeast-3 eci-vpc.ap-southeast-3.aliyuncs.com
印度尼西亚(雅加达) ap-southeast-5 eci-vpc.ap-southeast-5.aliyuncs.com
印度(孟买) ap-south-1 eci-vpc.ap-south-1.aliyuncs.com
日本(东京) ap-northeast-1 eci-vpc.ap-northeast-1.aliyuncs.com
美国(硅谷) us-west-1 eci-vpc.us-west-1.aliyuncs.com
美国(弗吉尼亚) us-east-1 eci-vpc.us-east-1.aliyuncs.com
德国(法兰克福) eu-central-1 eci-vpc.eu-central-1.aliyuncs.com
英国(伦敦) eu-west-1 eci-vpc.eu-west-1.aliyuncs.com
使用SDK过程中,您可以配置Endpoint对全局生效或者只对当前请求生效,实现内网调用API。Java代码示例如下:
DefaultProfile profile = DefaultProfile.getProfile("<RegionId>", "<AccessKeyId>", "<AccessKeySecret>");
IAcsClient client = new DefaultAcsClient(profile);

// 全局生效配置。其中,<product>为产品名称,弹性容器实例的值为Eci。
DefaultProfile.addEndpoint("<RegionId>", "<product>", "<Endpoint>");

// 只对当前请求生效配置。例如,调用DescribeRegions接口。
DescribeRegionsRequest regionsRequest = new DescribeRegionsRequest();
// 如果设置了productNetwork参数,则无需手动设置SysEndpoint。
regionsRequest.setSysEndpoint("<Endpoint>");
// 设置网络。productNetwork参数的取值范围:vpc、 public。其中,vpc表示内网调用,public表示公网调用,为默认选项。
regionsRequest.productNetwork = "vpc";
DescribeRegionsResponse regionsResponse = client.getAcsResponse(regionsRequest);