This topic describes how to create an Elastic Compute Service (ECS) instance from
an image family. You can only call the RunInstances or CreateInstance operation to create an ECS instance from an image family.
Prerequisites
One or more custom images are created, and the same image family is set for these
custom images. For more information, see Set an image family. In this example, the image family named image-test
is used.
Background information
When you create an ECS instance from an image family, the system automatically selects
the latest available custom image in the image family. The latest available custom
image is the available custom image that is created at the latest time in the image
family. For example, you have two available custom images in your image family. One
was created on January 1, 2020, and the other was created on January 3, 2020. When
you create an ECS instance from the image family, the system selects the custom image
that created on January 3, 2020 by default.
For more information about the operations called to create ECS instances, see RunInstances or CreateInstance. In this topic, the RunInstances operation is called.
Call the RunInstances operation to create an ECS instance
- Log on to OpenAPI Explorer.
- Call the RunInstances operation to create an ECS instance.
In this example, the
image-test
image family is used to create the instance. Specify the following API request parameters:
- RegionId: Specify the ID of the region. Example:
cn-hangzhou
.
- InstanceType: Specify the instance type of the instance. Example:
ecs.g6.large
.
- ImageFamily: Specify the image family name. Example:
image-test
.
- SecurityGroupId: Specify the ID of the security group. Example:
sg-bp1i4c0xgqxadew2****
.
- VSwitchId: Specify the ID of the vSwitch. Example:
vsw-bp1ddbrxdlrcbim46****
.
The following section shows a sample response. The ID of the created instance is displayed.
{
"RequestId": "409D4604-84D0-4F16-B99E-809E2E72****",
"InstanceIdSets": {
"InstanceIdSet": [
"i-bp1env7nl3mijm2t****"
]
}
}
Call an API operation to verify the image information
- Log on to OpenAPI Explorer.
- Call the DescribeImageFromFamily operation to query the latest available custom image in the specified image family.
In this example, the latest image in the
image-test
image family is queried. Specify the following API request parameters:
- RegionId: Specify the region ID of the image family.
- ImageFamily: Specify the image family name. Example:
image-test
.
The following figure shows a sample response. The ID of the latest available custom
image is displayed.

- Call the DescribeInstances operation to query the image information of an instance.
Query the ID of the image based on the ID of the instance and determine whether the
image is the latest available custom image in the image family. Specify the following
API request parameters:
- RegionId: Select the region ID of the instance.
- InstanceIds: Specify the instance ID in the
["i-bp1env7nl3mijm2t****"]
format.
The following figure shows a sample response. The image ID of the instance is the
same as the ID of the latest available custom image in the image family.
