一、术语
中文 | 英文 | 说明 |
---|---|---|
地域 | Region | 阿里云建设的数据中心。资源创建成功后无法更换地域。 |
可用区 | Zone | 同一地域内,电力和网络互相独立的物理数据中心。一个地域下可以有多个可用区。同一地域内可用区之间内网互通并且故障隔离,云服务器 ECS 网络延时低。 |
实例 | Instance | 采用虚拟化技术从阿里云物理服务器上虚拟出来的虚拟机,是一台云服务器 ECS 的基本计算单位。更多详情,请参阅 实例规格族。 |
镜像 | Image | 简称镜像,一般包含了操作系统和应用软件。新建实例的系统盘数据完全拷贝镜像,包括操作系统,软件配置等。您可以使用镜像初始化实例或者更换系统盘。 |
磁盘 | Disk | 云服务器 ECS 的存储设备。 |
安全组 | Security group | 虚拟防火墙,一台实例至少属于一个安全组。 |
快照 | Snapshot | 为磁盘创建的数据还原点,包含特定时刻磁盘数据。快照可以用于还原磁盘数据或创建镜像。 |
标签 | Tag | 由一对键值对(Key-Value)组成,为资源绑定标签便于快速筛选和分类。 |
IP 地址 | IP address | 云服务器 ECS 的公网或者私网 IP 地址。 |
二、ECS创建方式
支持 HTTP 或者 HTTPS 请求,允许 GET 和 POST 方法。可以通过以下方式调用云服务器 ECS API:
- (推荐)不同编程语言的云服务器 ECS SDK
- 阿里云 CLI
- 阿里云 API Explorer
- API URL 请求
三、Java SDK
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
<dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.4.1</version>
</dependency>
阿里云SDK调试
1、创建实例
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.ecs.model.v20140526.*;public class EcsDemo {public static void main(String[] args) {DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");IAcsClient client = new DefaultAcsClient(profile);CreateInstanceRequest request = new CreateInstanceRequest();request.setInternetChargeType("22");request.setInstanceName("fir");request.setSecurityGroupId("sg-bp15ed6xe1yxeycg7ov3");request.setInstanceType("ecs.g5.large");request.setImageId("win2008r2_64_ent_sp1_en-us_40G_alibase_20170915.vhd");try {CreateInstanceResponse response = client.getAcsResponse(request);System.out.println(new Gson().toJson(response));} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {System.out.println("ErrCode:" + e.getErrCode());System.out.println("ErrMsg:" + e.getErrMsg());System.out.println("RequestId:" + e.getRequestId());}}
}
2、创建EIP
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.ecs.model.v20140526.*;public class EcsDemo {public static void main(String[] args) {DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");IAcsClient client = new DefaultAcsClient(profile);AllocateEipAddressRequest request = new AllocateEipAddressRequest();try {AllocateEipAddressResponse response = client.getAcsResponse(request);System.out.println(new Gson().toJson(response));} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {System.out.println("ErrCode:" + e.getErrCode());System.out.println("ErrMsg:" + e.getErrMsg());System.out.println("RequestId:" + e.getRequestId());}}
}
3、启动实例
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.ecs.model.v20140526.*;public class EcsDemo {public static void main(String[] args) {DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");IAcsClient client = new DefaultAcsClient(profile);StartInstanceRequest request = new StartInstanceRequest();request.setInstanceId("i-sdoiwqnldsd");try {StartInstanceResponse response = client.getAcsResponse(request);System.out.println(new Gson().toJson(response));} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {System.out.println("ErrCode:" + e.getErrCode());System.out.println("ErrMsg:" + e.getErrMsg());System.out.println("RequestId:" + e.getRequestId());}}
}
四、REST API
API URL 请求需要自行验证身份和编码 URL。可以通过该方法了解阿里云访问验证流程。
创建AccessKey
请求结构
公共参数
签名机制
返回结果