匯入您已有的鏡像檔案到Elastic Compute Service,並作為自訂鏡像出現在相應地域中。
描述
匯入自訂鏡像後,您可以使用建立的自訂鏡像建立ECS執行個體(RunInstances)或者更換執行個體的系統盤(ReplaceSystemDisk)。調用該介面時,您需要注意:
- 您必須提前 上傳鏡像檔案到Object Storage Service。
- 匯入鏡像的地域必須跟鏡像檔案上傳的OSS Bucket的地域相同。
- 參數
DiskDeviceMapping.n中n的取值範圍為[1, 17]。n為1時表示系統盤,n為[2, 17]時表示資料盤。 - 不能刪除正在匯入的鏡像,只能取消匯入鏡像任務(CancelTask)。
- 您需要預先通過 存取控制RAM 服務為您授權ECS訪問OSS。參閱以下步驟:
- 建立角色
AliyunECSImageImportDefaultRole。必須是這個名稱,否則匯入鏡像會失敗。角色的策略為:{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "ecs.aliyuncs.com" ] } } ], "Version": "1" } - 在該角色下,添加權限原則
AliyunECSImageImportRolePolicy。這個策略是ECS匯入鏡像功能的預設策略,或者您也可以建立自訂策略,許可權需要包含:{ "Version": "1", "Statement": [ { "Action": [ "oss:GetObject", "oss:GetBucketLocation" ], "Resource": "*", "Effect": "Allow" } ] }
- 建立角色
請求參數
| 名稱 | 類型 | 是否必需 | 描述 |
|---|---|---|---|
| Action | String | 是 | 系統規定參數。取值:ImportImage |
| RegionId | String | 是 | 源自訂鏡像的地域ID。您可以調用DescribeRegions查看最新的阿里雲地域列表。 |
| ImageName | String | 否 | 鏡像名稱。
|
| Description | String | 否 | 鏡像的描述資訊。
|
| Architecture | String | 否 | 系統架構。取值範圍:
|
| OSType | String | 否 | 作業系統平台類型。取值範圍:
|
| Platform | String | 否 | 作業系統發行版。取值範圍:
|
| DiskDeviceMapping.n.Format | String | 否 | 鏡像格式。取值範圍:
|
| DiskDeviceMapping.n.OSSBucket | String | 是 | 鏡像檔案所在的OSS Bucket。 |
| DiskDeviceMapping.n.OSSObject | String | 是 | 鏡像檔案所在的OSS Object的檔案名稱(key)。 |
| DiskDeviceMapping.n.DiskImageSize | String | 否 | 鏡像大小。必須確保系統盤空間≥檔案系統空間。取值範圍:
|
返回參數
| 名稱 | 類型 | 描述 |
|---|---|---|
| RegionId | String | 地域ID |
| ImageId | String | 鏡像ID |
| ImportTaskId | String | 匯入鏡像任務ID |
樣本
請求樣本
https://ecs.aliyuncs.com/?Action=ImportImage
&RegionId=cn-hangzhou
&DiskDeviceMapping.1.OSSBucket=ecsimageos
&DiskDeviceMapping.1.OSSObject=CentOS_5.4_32.raw
&<公共請求參數>
返回樣本
XML格式
<ImportImageResponse>
<RequestId>C8B26B44-0189-443E-9816-D951F59623A9</RequestId>
<ImageId>Img-231234567</ImageId>
<ImportTaskId>123-345-2332-22323</ImportTaskId>
</ImportImageResponse>
JSON格式
{
"RequestId": "C8B26B44-0189-443E-9816-D951F59623A9",
"ImageId": "Img-231234567",
"ImportTaskId":"123-345-2332-22323"
}
錯誤碼
以下為本介面特有的錯誤碼。更多錯誤碼,請訪問 API錯誤中心 。
| 錯誤碼 | 錯誤資訊 | HTTP狀態碼 | 說明 |
|---|---|---|---|
| Forbbiden | User not authorized to operate on the specified resource | 400 | 您暫時無法匯入鏡像。 請 提交工單 聯繫阿里雲,為您開啟匯入鏡像功能。 |
| IncorrectImageStatus | The specified image is not available. | 400 | 指定的鏡像狀態不正確。 |
| InvalidArchitecture.Malformed | The specified Architecture is wrongly formed. | 400 | 指定的參數Architecture不合法。 |
| InvalidDescription.Malformed | The specified destination image description is wrongly formed. | 400 | 指定的參數Description不合法。 |
| InvalidFormat.Malformed | The specified Image format is wrongly formed. | 400 | 指定的鏡像檔案格式不合法。 |
| InvalidImageName.Duplicated | The destination image is exist. | 400 | 鏡像名稱已經重複。 |
| InvalidImageName.Malformed | The specified destination Image name is wrongly formed. | 400 | 指定的參數ImageName格式有誤。 |
| InvalidImageSize | The specified “DiskDeviceMapping.n.DiskImageSize” should be not less than system device size. | 400 | 指定的參數DiskDeviceMapping.n.DiskImageSize取值必須大於實際的磁碟大小。 |
| InvalidOSType.Malformed | The specified OSType is wrongly formed. | 400 | 指定的參數OSType不合法。 |
| InvalidPlatform.Malformed | The specified Platform is wrongly formed. | 400 | 指定的參數Platform不合法。 |
| MissingParameter | An input parameter “RegionId” that is mandatory for processing the request is not supplied. | 400 | 您需要指定必需參數RegionId。 |
| MissingParameter | An input parameter “DiskDeviceMapping.n.OSSBucket” that is mandatory for processing the request is not supplied. | 400 | 您需要指定必需參數OSSBucket。 |
| MissingParameter | An input parameter “DiskDeviceMapping.n.OSSObject” that is mandatory for processing the request is not supplied. | 400 | 您需要指定必需參數OSSObject。 |
| RegionId.NotFound | The specified region is not found. | 400 | 指定的RegionId不存在。 |
| ImageIsImporting | The specified Image is importing. | 403 | 指定的鏡像正在被複製中。請稍後再試。 |
| InvalidRegion.NotSupport | The specified region does not support image import or export. | 403 | 指定的地域暫時不支援匯入鏡像功能。 |
| QuotaExceed.Image | The Image Quota exceeds. | 403 | 您的自訂鏡像數已超出最高限制,不能再匯入鏡像。 |
| QuotaExceed.Snapshot | The maximum number of snapshots is exceeded. | 403 | 您的快照數已超出最高限制,不能再匯入鏡像。 |