All Products
Search
Document Center

Elastic Compute Service:ImportImage

Last Updated:Jun 18, 2026

Imports a local image file to Elastic Compute Service (ECS) as a custom image that appears in the specified region. You can then use the imported image to create ECS instances (RunInstances) or replace the system disk of an instance (ReplaceSystemDisk).

Operation description

Operation description

When you call this operation, take note of the following items:

  • You must upload the image file to Object Storage Service (OSS) in advance. For more information, see Upload files.

  • To prevent ECS instances created from the imported custom image from failing to start due to operating system issues on some servers, virtual machines, or cloud hosts, check whether you need to install the virtio driver on the source server before importing the image. For more information, see Install the virtio driver.

  • When you import an image for the first time, you must authorize ECS to access your OSS bucket by using Resource Access Management (RAM). Otherwise, the NoSetRoletoECSServiceAccount or InvalidOperation.CloudBoxImageImportRoleRequired error is returned. The following two scenarios apply:

    • Import an image file without using CloudBox: You can complete RAM authorization in the RAM console with a single click. For more information, see Cloud resource access authorization. You can also manually complete RAM authorization. The following policies and permissions are required for some operations. For more information, see Account access control.

      1. Create a role named AliyunECSImageImportDefaultRole. You must use this exact name. Otherwise, the image import fails. Use the following policy for the role:

        {
        	"Statement": [
        	{
        		"Action": "sts:AssumeRole",
        		"Effect": "Allow",
        		"Principal": {
        		"Service": [
        			"ecs.aliyuncs.com"
        		]
        		}
        	}
        ],
        	"Version": "1"
        }
        
      2. Attach the system policy AliyunECSImageImportRolePolicy to the role. You can also create a custom policy that includes the following permissions:

        {
        	"Version": "1",
        	"Statement": [
        	{
        		"Action": [
        				"oss:GetObject",
        				"oss:GetBucketLocation",
        				"oss:GetBucketInfo"
        	],
        			"Resource": "*",
        			"Effect": "Allow"
        			}
        	]
        }
        
        
    • Import an image file by using CloudBox: You can complete RAM authorization in the RAM console with a single click. For more information, see Cloud resource access authorization. You can also manually complete RAM authorization. The following policies and permissions are required for some operations. For more information, see Account access control.

      1. Create a role named AliyunECSCloudBoxImageImportDefaultRole. You must use this exact name. Otherwise, the image import fails. Use the following policy for the role:

        {
        	"Statement": [
        	{
        		"Action": "sts:AssumeRole",
        		"Effect": "Allow",
        		"Principal": {
        		"Service": [
        			"ecs.aliyuncs.com"
        		]
        		}
        	}
        ],
        	"Version": "1"
        }
        
      2. Attach the system policy AliyunECSCloudBoxImageImportRolePolicy to the role. You can also create a custom policy that includes the following permissions:

        {
        	"Version": "1",
        	"Statement": [
        	{
        		"Action": [
        				"oss-cloudbox:GetObject",
        				"oss-cloudbox:GetBucketLocation",
        				"oss-cloudbox:GetBucketInfo"
        	],
        			"Resource": "*",
        			"Effect": "Allow"
        			}
        	]
        }
        
        
  • You cannot delete an image that is being imported. You can only call CancelTask to cancel the image import task.

  • The region into which you import the image must be the same as the region of the OSS bucket to which the image file is uploaded.

  • Valid values of N in the DiskDeviceMapping.N parameter: 1 to 17. When N is 1, the disk is a system disk. When N is 2 to 17, the disk is a data disk. When N is greater than 17, the system automatically ignores the value.

  • When the Architecture parameter is set to arm64, or the Platform parameter is set to CentOS Stream, Anolis, AlmaLinux, UOS, Kylin, or Rocky Linux, take note of the following items:

    • To ensure that the imported image supports password configuration or key pair modification, the image must meet the following requirements:

      • The operating system kernel must support the CONFIG_FW_CFG_SYSFS feature. Linux community kernels later than version 4.6 support this feature by default. CentOS kernels later than version 3.10.0-826.el7 support this feature by default. You can run the grep -nr CONFIG_FW_CFG_SYSFS /boot/config-$(uname -r) command on the server that corresponds to the image. If the output contains CONFIG_FW_CFG_SYSFS=y, the kernel in the image supports the CONFIG_FW_CFG_SYSFS feature.

      • The latest version of Alibaba Cloud cloud-init is installed on the operating system. Cloud-init 19.1 must Milvus version 19.1.3 or later. Cloud-init 0.7.6a on some earlier operating systems must Milvus version 0.7.6a15 or later. For more information, see Install cloud-init.

      • The operating system must support the SHA-512 encryption algorithm.

    • To ensure that the imported image supports disk resizing and file system resizing, the image must meet the following requirements:

      • The operating system kernel version must be later than 3.6.

      • The growpart command is supported. To support this command, install the cloud-utils-growpart package. The installation method varies by operating system. For more information, see Resize partitions and file systems (Linux).

      • The resize2fs command is supported. To support this command, install the e2fsprogs package. This package is installed by default on the operating system. If it is not installed, install it manually.

      • The latest version of Alibaba Cloud cloud-init is installed on the operating system. Cloud-init 19.1 must Milvus version 19.1.3 or later. Cloud-init 0.7.6a on some earlier operating systems must Milvus version 0.7.6a15 or later. For more information, see Install cloud-init.

  • If the system architecture of the custom image that you want to import is arm64, set the RTC clock to use the UTC time standard. For more information, see Linux time and time zone description.

  • Configure the image detection parameters when you import an image. This helps the system optimize your image. For more information, see Image detection overview.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:ImportImage

update

*Image

acs:ecs:{#regionId}:{#accountId}:image/*

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

The region ID of the source custom image. You can call DescribeRegions to query the most recent region list.

cn-hangzhou

ImageName

string

No

The name of the image. The name must be 2 to 128 characters in length. It must start with a letter or a Chinese character and cannot start with aliyun or acs:. It cannot contain http:// or https://. It can contain digits, periods (.), colons (:), underscores (_), or hyphens (-).

ImageTestName

Description

string

No

The description of the image. The description must be 2 to 256 characters in length and cannot start with http:// or https://.

TestDescription

Architecture

string

No

The system architecture. Valid values:

  • i386.

  • x86_64.

  • arm64.

Default value: x86_64.

x86_64

OSType

string

No

The operating system type. Valid values:

  • windows. You must also set LicenseType.

  • linux.

Default value: linux.

linux

Platform

string

No

The operating system version. Valid values:

  • Aliyun

  • Anolis

  • CentOS

  • Ubuntu

  • CoreOS

  • SUSE

  • Debian

  • OpenSUSE

  • FreeBSD

  • RedHat

  • Kylin

  • UOS

  • Fedora

  • Fedora CoreOS

  • CentOS Stream

  • AlmaLinux

  • Rocky Linux

  • Gentoo

  • Customized Linux

  • Others Linux

  • Windows Server 2022

  • Windows Server 2019

  • Windows Server 2016

  • Windows Server 2012

  • Windows Server 2008

  • Windows Server 2003

  • Other Windows

Default value: Others Linux.

Aliyun

BootMode

string

No

The boot mode of the image. Valid values:

  • BIOS: BIOS boot mode.

  • UEFI: UEFI boot mode.

Default value: BIOS. If Architecture=arm64, the default value is UEFI, and only UEFI is supported.

Important

To prevent instances from failing to start due to an unsupported boot mode, make sure that you understand the boot mode supported by the target image before you set this parameter. For more information about image boot modes, see Image boot modes.

.

BIOS

RoleName

string

No

The name of the RAM role used to import the image.

AliyunECSImageImportDefaultRole

LicenseType

string

No

The license type. This parameter specifies the authorization mode when instances are created by calling RunInstances with the image. This value takes effect only for Windows Server images. Valid values:

  • Aliyun: Use the Alibaba Cloud official license. After the instance starts, the system attempts to automatically connect to the Alibaba Cloud KMS server for activation. The billing for the instance includes the Windows Server license fee.

  • BYOL: Bring Your Own License. After the instance starts, Alibaba Cloud does not automatically activate it. You must manually activate it by using your own valid license key. The billing for the instance does not include the Windows Server license fee.

Default value: Aliyun.

BYOL

ResourceGroupId

string

No

The ID of the enterprise resource group to which the imported image belongs.

rg-bp67acfmxazb4p****

DiskDeviceMapping

array<object>

No

The information list of the custom image to create.

object

No

The information list of the custom image to create.

DiskImSize

integer

No

The size of the custom image. Unit: GiB.

The size includes the system disk and data disks. Make sure that the system disk space is greater than or equal to the size of the imported image file. Valid values:

  • When N is 1, the value specifies the system disk size. Valid values: 1 to 2048.

  • When N is 2 to 17, the value specifies the data disk size. Valid values: 1 to 2048.

After you upload the source image file to OSS, you can view the image file size in the OSS bucket.

Note

This parameter will be deprecated. For better compatibility, use DiskDeviceMapping.N.DiskImageSize.

80

Device

string

No

The device name of DiskDeviceMapping.N.Device in the custom image.

Note

This parameter will be deprecated. For better compatibility, do not use this parameter.

null

OSSBucket

string

No

The OSS bucket where the image file is stored.

Note

Before you import an image to this OSS bucket for the first time, add the RAM authorization policy as described in the Operation description section of this topic. Otherwise, the NoSetRoletoECSServiceAccount error is returned.

ecsimageos

Format

string

No

The image format. Valid values:

  • RAW.

  • VHD.

  • QCOW2.

  • VMDK (in invitational preview).

Default value: null, which indicates that Alibaba Cloud automatically detects the image format. The detected format prevails.

QCOW2

OSSObject

string

No

The file name (key) of the image file stored in the OSS bucket after the image is uploaded to OSS.

CentOS_5.4_32.raw

DiskImageSize

integer

No

The size of the custom image after the image is imported.

The size includes the system disk and data disks. Make sure that the system disk space is greater than or equal to the size of the imported image file. Valid values:

  • When N is 1, the value specifies the system disk size. Valid values: 1 to 2048. Unit: GiB.

  • When N is 2 to 17, the value specifies the data disk size. Valid values: 1 to 2048. Unit: GiB.

After you upload the source image file to OSS, you can view the image file size in the OSS bucket.

80

Tag

array<object>

No

The tags of the image.

object

No

The tags of the image.

Key

string

No

The key of the image tag. Valid values of N: 1 to 20. The tag key cannot be an empty string. The tag key can be up to 128 characters in length and cannot start with aliyun or acs:. It cannot contain http:// or https://.

TestKey

Value

string

No

The value of the image tag. Valid values of N: 1 to 20. The tag value can be an empty string. The tag value can be up to 128 characters in length and cannot start with acs:. It cannot contain http:// or https://.

TestValue

DetectionStrategy

string

No

The image detection strategy. If this parameter is not specified, detection is not triggered. Only the Standard detection mode is supported.

Note

Most Linux and Windows versions are supported. For more information about image detection items and operating system limitations, see Image detection overview and Operating system limitations for image detection.

Standard

StorageLocationArn

string

No

The Alibaba Cloud Resource Name (ARN) of the CloudBox, which is used to uniquely identify the cloud storage location.

Note

You need to specify this parameter only when you import an image file from OSS on CloudBox. If you do not use OSS on CloudBox, do not set this parameter. For more information, see What is OSS on CloudBox.

The ARN must follow this format: arn:acs:cloudbox:{RegionId}:{AliUid}:cloudbox/{CloudBoxId}, where {RegionId} is the region ID of the CloudBox, {AliUid} is the Alibaba Cloud account ID, and {CloudBoxId} is the CloudBox ID.

arn:acs:cloudbox:cn-hangzhou:123456:cloudbox/cb-xx***123

DryRun

boolean

No

Specifies whether to perform only a dry run. Valid values:

  • true: performs only a dry run. The system checks the request for potential issues, including invalid AccessKey pairs, unauthorized RAM users, and missing parameter values. If the request fails the dry run, the corresponding error message is returned. If the request passes the dry run, the DryRunOperation error code is returned.

  • false: performs a dry run and sends the request. If the request passes the dry run, a 2XX HTTP status code is returned and the resource status is queried.

Default value: false.

false

Features

object

No

The image feature-related properties.

NvmeSupport

string

No

Specifies whether the image supports NVMe. Valid values:

  • supported: Instances created from this image support NVMe.

  • unsupported: Instances created from this image do not support NVMe.

supported

ImdsSupport

string

No

The metadata access mode of the image. Valid values:

  • v1: When you create an ECS instance from this image, you cannot set the metadata access mode to hardened mode only.

  • v2: When you create an ECS instance from this image, you can set the metadata access mode to hardened mode only.

Default value: v1.

v2

ClientToken

string

No

The client token that is used to ensure the idempotence of the request. You can use the client to generate the token, but make sure that the token is unique among different requests. The ClientToken value can contain only ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

123e4567-e89b-12d3-a456-426655440000

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3****

ImageId

string

The image ID.

m-bp67acfmxazb4p****

TaskId

string

The ID of the image import task.

t-bp67acfmxazb4p****

RegionId

string

The region ID.

cn-hangzhou

Examples

Success response

JSON format

{
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3****",
  "ImageId": "m-bp67acfmxazb4p****",
  "TaskId": "t-bp67acfmxazb4p****",
  "RegionId": "cn-hangzhou"
}

Error codes

HTTP status code

Error code

Error message

Description

400 UnsupportedSuffix.OSSObject The specified OSS object suffix is not supported.
400 MissingParameter An input parameter "RegionId" that is mandatory for processing the request is not supplied.
400 InvalidImageName.Malformed The specified Image name is wrongly formed. The specified image name is invalid. The name must be 2 to 128 characters in length. It must start with a letter and cannot start with acs: or aliyun. It can contain letters, digits, periods (.), colons (:), underscores (_), and hyphens (-). It cannot contain http:// or https://.
400 InvalidOSSObject.Malformed The specified OSS object is wrongly formed. The specified OSS object is invalid.
400 InvalidOSSBucket.Malformed The specified OSS bucket is wrongly formed.
400 InvalidOSSObject.Size The specified OSS object size is zero. The specified OSSObject is empty
400 InvalidDescription.Malformed The specified Image description is wrongly formed. The image description is invalid.
400 InvalidArchitecture.Malformed The specified Architecture is wrongly formed. The specified Architecture parameter is invalid.
400 InvalidPlatform.Malformed The specified Platform is wrongly formed.
400 InvalidOSType.Malformed The specified OSType is wrongly formed. The specified OS type is invalid.
400 InvalidImageName.Duplicated The destination image is exist.
400 InvalidImageSize %s The specified image size is invalid.
400 InvalidDataDiskSize The specified DiskDeviceMapping.N.DiskImSize should be in the specified range. The specified DiskDeviceMapping.N.DiskImSize parameter is invalid.
400 InvalidImageFormat.Malformed The specified Image Format is wrongly formed. The specified image format is invalid.
400 InvalidRegionId.NotFound The specified RegionId does not exist.
400 InvalidRegion.NotSupport The specified region does not support image import or export. The specified region does not support the operation.
400 InvalidOSSBucket.NotFound The specified OSS bucket does not exist in this region. The specified bucket does not exist.
400 InvalidOSSObject.NotFound The specified OSS object does not exist in this region.
400 InvalidOSSObject.NeedRestore The specified OSS object is a archive object, need restore first.
400 InvalidOSSBucket.NotMatched The specified OSS bucket is incorrect, %s. The specified DiskDeviceMapping.N.OSSBucket parameter is invalid. For more information, see the return value of the %s placeholder in the error message.
400 InvalidLicenseType.NotSupported The specified LicenseType is not supported.
400 InvalidLicenseType.BYOLOnly Only BYOL LicenseType is supported for the current platform provided.
400 InvalidOSSBucket.FlowLimit %s
400 InvalidImageFormat.RegionNotSupported The specified image format is not supported in current region.
400 InvalidBootMode.Malformed The specified parameter "BootMode" is malformed.
400 InvalidParameter.DetectionStrategy The specified parameter DetectionStrategy is invalid.
400 InvalidBootMode.NotSupport The specified parameter BootMode is not supported for current image architecture. The current image architecture does not support setting this boot mode.
400 DRYRUN.SUCCESS This request is a dryrun request with successful result. The request is checked and determined as valid.
400 InvalidClientToken.Malformed The specified parameter clientToken is not valid.
400 InvalidParameter.FeaturesImdsSupport The specified parameter Features.ImdsSupport is not supported. The specified parameter Features.ImdsSupport is not supported.
400 Account.Arrearage Your account has an outstanding payment. Your account has overdue payments.
403 ImageIsImporting The specified Image is importing.
403 QuotaExceed.Image The Image Quota exceeds.
403 ImportImageFailed Importing image is failed, Please contact the administrator. The image cannot be imported. Contact your system administrator.
403 UserNotInTheWhiteList The user is not in the white list of importing image.
403 NoSetRoletoECSServiceAcount ECS service account Have no right to access your OSS.please attach a role of access your oss to ECS service account.
403 InvalidParameter.Malformed The specified parameter "DiskDeviceMapping.n.Device " is not valid.
403 MissingParameter.DiskDeviceMapping The specified parameter DiskDeviceMapping is not supplied. A parameter that starts with DiskDeviceMapping must be specified.
403 InvalidOSS.NotAuthorized The specified OSS bucket or object is not allowed to access. You do not have the permission to access the specified OSS bucket and object.
403 InvalidBlockSize.NotSupport %s
403 InvalidImageFormat.Malformed %s
403 ImageCheckUnsupported.WindowsImage Image check is unsupported for windows image.
403 InvalidVHDImage.IncorrectSize The specified size of the VHD image does not meet the 'header.MaxTableEntries * header.BlockSize' specification. The size of the specified VHD image does not meet the header.MaxTableEntries × header.BlockSize size limit.
403 InvalidOSSBucket.EncryptUnsupported Accessing objects from encrypted OSS bucket is not supported. You cannot read objects from encrypted OSS buckets.
403 InvalidArchitecture.PlatformUnsupported The OS platform you selected does not support the specified architecture. The selected operating system does not support the specified architecture type.
403 InvalidAccountStatus.OSSDisabled OSS is disabled due to invalid account status.
403 InvalidStorageLocation.NotFound The specified cloud box storage location %s could not be found. The specified cloud box storage location could not be found.
403 InvalidOperation.CloudBoxImageImportRoleRequired The role for cloud box image import is not set to the ECS service. The role for cloud box image import is not set to the ECS service.
403 InvalidOperation.CloudBoxImageImportUnsupported Importing cloud box images is not supported. Importing cloud box images is not supported.
403 TagKey.Duplication The TagKey has duplication with others, case-insensitive. Duplicate values exist in the specified Tag.N.Key parameter. The value of this parameter is not case sensitive. Check whether duplicate parameter values are passed in.
404 InvalidResourceGroup.NotFound The ResourceGroup provided does not exist in our records. The specified resource group does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.