All Products
Search
Document Center

Elastic Compute Service:Create an ECS instance from an image family

Last Updated:Jan 29, 2024

You can create an Elastic Compute Service (ECS) instance based on the ImageFamily parameter by calling an API operation. The system automatically selects the latest available image in the image family for the ECS instance. This topic describes how to create an ECS instance from an image family.

Procedure

  1. Log on to OpenAPI Explorer.

  2. Call the RunInstances operation to create an ECS instance.

    In this example, an ECS instance is created by using an image family named image-test. Specify the following API request parameters:

    • RegionId: Specify the region ID. Example: cn-hangzhou.

    • InstanceType: Specify the instance type. Example: ecs.g6.large.

    • ImageFamily: Specify the image family. Example: image-test.

    • SecurityGroupId: Specify the ID of a security group. Example: sg-bp1i4c0xgqxadew2****.

    • VSwitchId: Specify the vSwitch ID. Example: vsw-bp1ddbrxdlrcbim46****.

    The following section shows a sample response, in which the ID of the created instance is displayed:

    {
        "RequestId": "409D4604-84D0-4F16-B99E-809E2E72****",
        "InstanceIdSets": {
            "InstanceIdSet": [
                "i-bp1env7nl3mijm2t****"
            ]
        }
    }
  3. Verify the image information of the ECS instance.

    1. Call the DescribeImageFromFamily operation to query the latest custom available 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. Example: image-test.

      The following figure shows a sample response, in which the ID of the lastest available custom image is displayed.11

    2. Call the DescribeInstances operation to query the image information of an instance.

      Query the ID of the image based on the instance ID and determine whether the image is the latest custom available 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 format of ["i-bp1env7nl3mijm2t****"].

      The following example shows a part of a sample response. The image ID of the instance is the same as the ID of the latest available image in the image family.if8