All Products
Search
Document Center

Resource Orchestration Service:ALIYUN::ECS::InstanceGroup

Last Updated:May 05, 2023

ALIYUN::ECS::InstanceGroup is used to create a group of Elastic Compute Service (ECS) instances that have the same configurations.

Syntax

{
  "Type": "ALIYUN::ECS::InstanceGroup",
  "Properties": {
    "DedicatedHostId": String,
    "ResourceGroupId": String,
    "SystemDiskDescription": String,
    "InstanceChargeType": String,
    "RamRoleName": String,
    "SystemDiskPerformanceLevel": String,
    "ImageId": String,
    "SystemDiskDiskName": String,
    "Tags": List,
    "HostName": String,
    "LaunchTemplateName": String,
    "VSwitchId": String,
    "Period": Number,
    "ZoneIds": List,
    "LaunchTemplateId": String,
    "DeletionProtection": "Boolean",
    "SecurityGroupIds": List,
    "SecurityEnhancementStrategy": String,
    "InternetChargeType": String,
    "InstanceName": String,
    "DeploymentSetId": String,
    "InternetMaxBandwidthOut": Integer,
    "VpcId": String,
    "LaunchTemplateVersion": String,
    "PeriodUnit": String,
    "AutoReleaseTime": String,
    "PrivateIpAddress": String,
    "Description": String,
    "DiskMappings": List,
    "SystemDiskSize": Number,
    "UserData": String,
    "AutoRenew": String,
    "Ipv6Addresses": List,
    "MaxAmount": Integer,
    "SystemDiskAutoSnapshotPolicyId": String,
    "Ipv6AddressCount": Integer,
    "NetworkType": String,
    "SpotPriceLimit": String,
    "InstanceType": String,
    "AllocatePublicIP": "Boolean",
    "SpotStrategy": String,
    "Password": String,
    "PasswordInherit": Boolean,
    "AutoRenewPeriod": Number,
    "KeyPairName": String,
    "IoOptimized": String,
    "ZoneId": String,
    "HpcClusterId": String,
    "SecurityGroupId": String,
    "SystemDiskCategory": String,
    "EniMappings": List,
    "SystemDiskProvisionedIops": Integer,
    "SystemDiskBurstingEnabled": Boolean,
    "SpotInterruptionBehavior": String,
    "SpotDuration": Integer,
    "UpdatePolicy": String,
    "SystemDiskEncrypted": String,
		"SystemDiskEncryptAlgorithm": String,
		"SystemDiskStorageClusterId": String,
		"SystemDiskKMSKeyId": String
  }
}

Properties

Property

Type

Required

Editable

Description

Constraint

ResourceGroupId

String

No

Yes

The ID of the resource group to which the instance belongs.

None.

SpotInterruptionBehavior

String

No

No

The interruption mode of the preemptible instance.

Set the value to Terminate (default). A value of Terminate specifies that the instance is released.

SpotDuration

Integer

No

No

The retention period of the preemptible instance.

Valid values: 0 to 6.

Unit: hour.

Valid values:

  • 0: If you set this property to 0, the preemptible instance does not have a protection period.

  • 2, 3, 4, 5, and 6: The retention periods of 2, 3, 4, 5, and 6 hours are in invitational preview. If you want to set this property to one of the values, submit a ticket.

  • 1 (default).

HpcClusterId

String

No

Yes

The ID of the Elastic High Performance Computing (E-HPC) cluster to which the instance belongs.

Updates to this property take effect only for new ECS instances.

MaxAmount

Integer

Yes

Yes

The number of ECS instances that you can create at a time.

Valid values: 1 to 1000.

Note

If you increase or decrease the value of MaxAmount when you update the stack that references the property, the number of ECS instances is increased or decreased based on the new value. For example, if you change the value of MaxAmount from 2 to 5, three ECS instances are added.

Description

String

No

Yes

The description of the instance.

The description can be up to 256 characters in length.

Note

Updates to this property take effect only for new ECS instances.

InstanceType

String

Yes

Yes

The ECS instance type.

For more information, see Overview of instance families.

Note

This property can be updated when UpdatePolicy is set to ForAllInstance.

ImageId

String

Yes

Yes

The ID of the image that is used to start the ECS instance. You can use a public image, a custom image, or an Alibaba Cloud Marketplace image.

If you specify a part of a public image ID, the system can match the complete ID of the public image. You do not need to specify the complete ID of the public image. Examples:

  • If you specify ubuntu, the system matches the following complete image ID: ubuntu_16_0402_64_20G_alibase_20170818.vhd.

  • If you specify ubuntu1432, the system matches the following complete image ID: ubuntu_14_0405_32_40G_alibase_20170711.vhd.

For more information, see Request parameters.

SecurityGroupId

String

No

No

The ID of the security group to which the instance belongs. Instances that belong to the same security group can communicate with each other.

You cannot specify both SecurityGroupId and SecurityGroupIds.

SecurityGroupIds

List

No

No

The IDs of the security groups to which the instances belong.

You cannot specify both SecurityGroupId and SecurityGroupIds.

For more information, see Security groups.

SecurityEnhancementStrategy

String

No

No

Specifies whether to enable security hardening.

Valid values:

  • Active: enables security hardening. This value is valid only for public images.

  • Deactive: disables security hardening. This value is valid for all types of images.

InstanceName

String

No

No

The name of the instance.

The name can be up to 128 characters in length and can contain letters, digits, underscores (_), periods (.), and hyphens (-).

The name must be in the name_prefix[begin_number,bits]name_suffix format. The name of each ECS instance must be unique. For more information, see Request parameters.

Password

String

No

Yes

The password that you want to use to log on to the instance.

The password must be 8 to 30 characters in length. The password must contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include : ( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ' < > , . ? /.

If you specify Password, we recommend that you call the Resource Orchestration Service (ROS) API by using HTTPS to prevent the exposure of your password.

PasswordInherit

Boolean

No

No

Specifies whether to use the preset password of the image.

Valid values:

  • true

  • false

Note

If you set this property to true, leave Password empty and make sure that the selected image has a preset password.

ZoneIds

List

No

No

The IDs of the zones.

None.

HostName

String

No

No

The hostname of the instance.

The hostname must be at least two characters in length. The hostname cannot contain consecutive periods (.) or hyphens (-). The hostname cannot start or end with a period (.) or hyphen (-).

For more information, see Request parameters.

AllocatePublicIP

Boolean

No

No

Specifies whether to assign a public IP address.

If you set InternetMaxBandwidthOut to 0, the system does not assign a public IP address.

Valid values:

  • true (default)

  • false

AutoReleaseTime

String

No

No

The time at which the system automatically releases the instance.

Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time must be within three years from the time at which the instance is created.

PrivateIpAddress

String

No

No

The private IP address of the instance.

If you configure a private IP address for an ECS instance in a virtual private cloud (VPC), you must select an idle IP address from the CIDR block of the vSwitch.

Note

If you specify PrivateIpAddress, you must set MaxAmount to 1.

DiskMappings

List

No

Yes

The data disks that you want to create for the instance.

You can create up to 16 data disks.

If you change the value of this property, existing instances are not affected. The new value is valid for new instances.

For more information, see DiskMappings properties.

Note

Updates to this property take effect only for new ECS instances.

InternetChargeType

String

No

Yes

The metering method for Internet usage.

Valid values:

  • PayByBandwidth

  • PayByTraffic (default)

Note

This property can be updated when UpdatePolicy is set to ForAllInstance.

InternetMaxBandwidthOut

Integer

No

Yes

The maximum outbound public bandwidth.

Valid values: 0 to 100.

Unit: Mbit/s.

Default value: 0.

Note

This property can be updated when UpdatePolicy is set to ForAllInstance.

SystemDiskProvisionedIops

Integer

No

Yes

The IOPS that is preset in the system disk.

None.

SystemDiskBurstingEnabled

Boolean

No

Yes

Specifies whether to enable the burst mode for the system disk.

Valid values:

  • true

  • false (default)

IoOptimized

String

No

No

Specifies whether to create an I/O optimized instance.

Valid values:

  • none: does not create an I/O optimized instance.

  • optimized (default): creates an I/O optimized instance.

SystemDiskCategory

String

No

Yes

The category of the system disk.

Valid values:

  • cloud: basic disk

  • cloud_efficiency: ultra disk

  • cloud_ssd: standard SSD

  • cloud_essd: enhanced SSD (ESSD)

  • ephemeral_ssd: local SSD

Note

Updates to this property take effect only for new ECS instances.

SystemDiskDescription

String

No

Yes

The description of the system disk.

Updates to this property take effect only for new ECS instances.

SystemDiskDiskName

String

No

Yes

The name of the system disk.

Updates to this property take effect only for new ECS instances.

SystemDiskSize

Number

No

Yes

The size of the system disk.

Valid values: 40 to 500.

Unit: GB.

If you use a custom image to create a system disk, make sure that the size of the system disk is larger than the size of the custom image.

Note

This property can be updated when UpdatePolicy is set to ForAllInstance.

Tags

List

No

Yes

The tags to add to the instance.

You can specify up to 20 tags in the following format: [{"Key":"tagKey","Value":"tagValue"},{"Key":"tagKey2","Value":"tagValue2"}].

For more information, see Tags syntax.

UserData

String

No

Yes

The user data that you want to pass when you create the instance.

The user data can be up to 16 KB in size. You do not need to convert the data to Base64-encoded strings. If the data contains special characters, you must add the escape character (\) before each special character.

ZoneId

String

No

No

The zone ID.

None.

VpcId

String

No

No

The VPC ID.

None.

VSwitchId

String

No

No

The vSwitch ID.

None.

KeyPairName

String

No

Yes

The name of the key pair that you want to use to connect to the instance.

For Windows ECS instances, this property is ignored. By default, this property is empty.

If you specify both KeyPairName and Password, the value of Password is used for the ECS instance. For Linux ECS instances, password-based logons are disabled.

Note

Updates to this property take effect only for new ECS instances.

RamRoleName

String

No

Yes

The name of the RAM role for the instance.

You can call the ListRoles operation to query the names of RAM roles. For more information, see CreateRole and ListRoles.

SpotPriceLimit

String

No

No

The maximum hourly price of the instance.

The value of this property can contain up to three decimal places. This property takes effect when SpotStrategy is set to SpotWithPriceLimit.

SpotStrategy

String

No

No

The bidding policy for the pay-as-you-go instance.

This property takes effect when InstanceChargeType is set to PostPaid.

Valid values:

  • NoSpot (default): The instance is created as a regular pay-as-you-go instance.

  • SpotWithPriceLimit: The instance is created as a preemptible instance for which you specify the maximum hourly price.

  • SpotAsPriceGo: The instance is created as a preemptible instance for which the market price at the time of purchase is automatically used as the bid price. The market price can be up to the pay-as-you-go price.

DedicatedHostId

String

No

No

The ID of the dedicated host.

None.

LaunchTemplateName

String

No

Yes

The name of the launch template.

None.

PeriodUnit

String

No

Yes

The unit of the subscription duration of the instance.

Valid values:

  • Week

  • Month (default)

Note

Updates to this property take effect only for new ECS instances.

AutoRenewPeriod

Number

No

Yes

The auto-renewal period for the instance.

This property must be specified when AutoRenew is set to True.

Valid values:

  • 1 (default)

  • 2

  • 3

  • 6

  • 12

Note

Updates to this property take effect only for new ECS instances.

AutoRenew

String

No

Yes

Specifies whether to enable auto-renewal for the instance.

This property takes effect when InstanceChargeType is set to PrePaid.

Valid values:

  • True

  • False (default)

Note

Updates to this property take effect only for new ECS instances.

InstanceChargeType

String

No

Yes

The billing method of the instance.

Valid values:

  • PrePaid: the subscription billing method.

    Note

    If you want to set this property to PrePaid, make sure that your account has sufficient balance or credit. If your account has insufficient balance or credit, an InvalidPayMethod error is returned.

  • PostPaid (default): the pay-as-you-go billing method.

Note

Updates to this property take effect only for new ECS instances.

EniMappings

List

No

Yes

The elastic network interface (ENI) that you want to attach to the instance.

You can attach only one ENI to an instance.

For more information, see EniMappings properties.

LaunchTemplateId

String

No

Yes

The ID of the launch template.

None.

LaunchTemplateVersion

String

No

Yes

The version of the launch template.

If you do not specify a version, the default version is used.

Period

Number

No

Yes

The subscription period of the instance.

This property must be specified when InstanceChargeType is set to PrePaid.

If you specify DedicatedHostId, the value of Period must be within the subscription period of the dedicated host.

  • Valid values when PeriodUnit is set to Week: 1, 2, 3, and 4.

  • Valid values when PeriodUnit is set to Month: 1, 2, 3, 4, 5, 6, 7, 8, 9, 12, 24, 36, 48, and 60.

Note

Updates to this property take effect only for new ECS instances.

NetworkType

String

No

No

The network type of the instance.

Valid values:

  • vpc

  • classic (default)

DeletionProtection

Boolean

No

Yes

The release protection attribute of the instance. This property indicates whether you can use the ECS console or call the DeleteInstance operation to release the instance.

Valid values:

  • true

  • false

DeploymentSetId

String

No

Yes

The ID of the deployment set.

Updates to this property take effect only for new ECS instances.

Ipv6AddressCount

Integer

No

Yes

The number of randomly generated IPv6 addresses that are assigned to the ENI.

You cannot specify both Ipv6Addresses and Ipv6AddressCount.

Note

Updates to this property take effect only for new ECS instances.

Ipv6Addresses

List

No

Yes

The IPv6 address that is assigned to the ENI.

You can specify only one IPv6 address. If you change the value of this property, existing instances are not affected. You cannot specify both Ipv6Addresses and Ipv6AddressCount.

Note

Updates to this property take effect only for new ECS instances.

SystemDiskAutoSnapshotPolicyId

String

No

Yes

The ID of the automatic snapshot policy for the system disk.

None.

SystemDiskPerformanceLevel

String

No

No

The performance level (PL) of the ESSD that is used as the system disk.

Valid values:

  • PL0: An ESSD delivers up to 10,000 random read/write IOPS.

  • PL1 (default): An ESSD delivers up to 50,000 random read/write IOPS.

  • PL2: An ESSD delivers up to 100,000 random read/write IOPS.

  • PL3: An ESSD delivers up to 1,000,000 random read/write IOPS.

For more information about how to select the PLs of ESSDs, see ESSDs.

UpdatePolicy

String

No

Yes

The update policy that you want to use for instances.

Valid values:

  • ForNewInstance (default): The update policy takes effect for new instances.

  • ForAllInstances: The update policy takes effect for all instances.

SystemDiskEncrypted

String

No

Yes

Specifies whether to encrypt the system disk.

Valid values:

  • true

  • false

SystemDiskEncryptAlgorithm

String

No

Yes

The encryption algorithm that you want to use for the system disk.

Valid values:

  • AES-256

  • SM4-128

SystemDiskStorageClusterId

String

No

Yes

The ID of the dedicated block storage cluster in which the system disk resides.

None.

SystemDiskKMSKeyId

String

No

Yes

The ID of the Key Management Service (KMS) key that you want to use to encrypt the system disk.

None.

DiskMappings syntax

"DiskMappings": [
  {
    "Category": String,
    "DiskName": String,
    "Description": String,
    "Device": String,
    "SnapshotId": String,
    "Size": String,
    "Encrypted": String,
    "KMSKeyId": String,
    "PerformanceLevel": String,
    "AutoSnapshotPolicyId": String,
    "ProvisionedIops": Integer,
    "BurstingEnabled": Boolean
  }
]

DiskMappings properties

Property

Type

Required

Editable

Description

Constraint

Size

String

Yes

No

The size of the data disk.

Unit: GB.

Category

String

No

No

The category of the data disk.

Valid values:

  • cloud: basic disk

  • cloud_efficiency: ultra disk

  • cloud_ssd: standard SSD

  • cloud_essd: ESSD

  • ephemeral_ssd: local SSD

For I/O optimized instances, the default value is cloud_efficiency.

For non-I/O optimized instances, the default value is cloud.

DiskName

String

No

No

The name of the data disk.

The name must be 2 to 128 characters in length and can contain letters, digits, underscores (_), colons (:), and hyphens (-). The name must start with a letter and cannot start with http:// or https://.

Description

String

No

No

The description of the data disk.

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

Device

String

No

No

The mount target of the data disk.

Note

This property will be removed in the future. We recommend that you use other properties to improve compatibility.

SnapshotId

String

No

No

The snapshot ID.

None.

Encrypted

String

No

No

Specifies whether to encrypt the data disk.

Valid values:

  • true

  • false (default)

KMSKeyId

String

No

No

The ID of the KMS key that you want to use to encrypt the data disk.

None.

AutoSnapshotPolicyId

String

No

No

The ID of the automatic snapshot policy.

None.

PerformanceLevel

String

No

No

The PL of the ESSD that is used as the data disk.

Valid values:

  • PL0: An ESSD delivers up to 10,000 random read/write IOPS.

  • PL1 (default): An ESSD delivers up to 50,000 random read/write IOPS.

  • PL2: An ESSD delivers up to 100,000 random read/write IOPS.

  • PL3: An ESSD delivers up to 1,000,000 random read/write IOPS.

For more information, see ESSDs.

ProvisionedIops

Integer

No

No

The IOPS that is preset in the data disk.

None.

BurstingEnabled

Boolean

No

No

Specifies whether to enable the burst mode for the data disk.

Valid values:

  • true

  • false (default)

Tags syntax

"Tags": [
  {
    "Value": String,
    "Key": String
  }
]

Tags properties

Property

Type

Required

Editable

Description

Constraint

Key

String

Yes

No

The key of the tag.

The tag key must be 1 to 128 characters in length and cannot contain http:// or https://. The tag key cannot start with aliyun or acs:.

Value

String

No

No

The value of the tag.

The tag value can be up to 128 characters in length and cannot contain http:// or https://. The tag value cannot start with aliyun or acs:.

EniMappings syntax

"EniMappings": [
  {
    "SecurityGroupId": String,
    "VSwitchId": String,
    "Description": String,
    "NetworkInterfaceName": String,
    "PrimaryIpAddress": String
  }
]

EniMappings properties

Property

Type

Required

Editable

Description

Constraint

SecurityGroupId

String

Yes

Yes

The ID of the security group to which the ENI belongs.

The security group and the ECS instance must be deployed in the same VPC.

VSwitchId

String

Yes

No

The ID of the vSwitch to which the ENI is connected.

None.

Description

String

No

Yes

The description of the ENI.

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

NetworkInterfaceName

String

No

Yes

The name of the ENI.

The name must be 2 to 128 characters in length and can contain letters, digits, colons (:), underscores (_), and hyphens (-). The name must start with a letter and cannot start with http:// or https://.

PrimaryIpAddress

String

No

No

The primary private IP address of the ENI.

The IP address must be an idle IP address within the CIDR block of the vSwitch.

If you leave this property empty, the system randomly assigns an idle IP address from the CIDR block of the vSwitch.

Return values

Fn::GetAtt

  • InstanceIds: the IDs of the instances. An instance ID is a GUID that is generated by the system for an instance.

  • PrivateIps: the private IP addresses of instances in the VPC. This property takes effect when NetworkType is set to vpc. The value is a JSON array that can contain up to 100 IP addresses separated by commas (,). Example: ["172.16.XX.XX", "172.16.XX.XX", … "172.16.XX.XX"].

  • InnerIps: the private IP addresses of instances in the classic network. This property takes effect when NetworkType is set to classic. The value is a JSON array that can contain up to 100 IP addresses separated by commas (,). Example: ["10.1.XX.XX", "10.1.XX.XX", … "10.1.XX.XX"].

  • PublicIps: the public IP addresses of instances in the classic network. This property takes effect when NetworkType is set to classic. The value is a JSON array that can contain up to 100 IP addresses separated by commas (,). Example: ["42.1.XX.XX", "42.1.XX.XX", … "42.1.XX.XX"].

  • HostNames: the hostnames of the instances.

  • OrderId: the order ID of the instances.

  • ZoneIds: the zone IDs of the instances.

  • Ipv6AddressIds: the IDs of IPv6 addresses of the instances.

    Note

    The IPv6 address IDs are returned in a list that has two levels of nesting. If an ECS instance does not have an IPv6 address, the element at the relevant position in the list is empty. If none of the ECS instances have an IP address, null is returned.

  • Ipv6Addresses: the IPv6 addresses of the instances.

    Note

    The IPv6 addresses are returned in a list that has two levels of nesting. If an ECS instance does not have an IPv6 address, the element at the relevant position in the list is empty. If none of the ECS instances have an IP address, null is returned.

Examples

The following sample code provides examples on how to create the OpsEcsInstance and ProdEcsInstance ECS instances and configure password-free logon for the ProdEcsInstance instance.

If you want to receive signals of the execution results of user-data scripts of the ECS instance, you can configure ALIYUN::ROS::WaitCondition and ALIYUN::ROS::WaitConditionHandle. For more information, see ALIYUN::ROS::WaitConditionHandle and ALIYUN::ROS::WaitCondition.

  • YAML format

    ROSTemplateFormatVersion: '2015-09-01'
    Description: Creates VPC ECS instance
    Parameters:
      VpcId:
        AssociationProperty: ALIYUN::ECS::VPC::VPCId
        Type: String
        Description:
          en: Please search the ID starting with (vpc-xxx) from console-Virtual Private Cloud
           
        Label:
          en: VPC ID
           
      VSwitchZoneId:
        AssociationProperty: ALIYUN::ECS::Instance:ZoneId
        Type: String
        Description:
           
          en: VSwitch Availability Zone
        Label:
           
          en: VSwitch Availability Zone
      VSwitchId:
        AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
        AssociationPropertyMetadata:
          VpcId: ${VpcId}
          ZoneId: ${VSwitchZoneId}
        Type: String
        Description:
          en: Instance ID of existing business network switches, console-Virtual Private Cloud-VSwitches under query
           
        Label:
          en: VSwitch ID
           
      SecurityGroupId:
        Type: String
        AssociationProperty: ALIYUN::ECS::SecurityGroup::SecurityGroupId
        AssociationPropertyMetadata:
          VpcId: ${VpcId}
        Description:
          en: Please search the business security group ID starting with(sg-xxx)from console-ECS-Network & Security
           
        Label:
          en: Business Security Group ID
           
      InstanceType:
        Type: String
        Description:
           
          en: Fill in the specifications that can be used under the VSwitch availability zone.
        Label:
           
          en: Instance Type
        AssociationProperty: ALIYUN::ECS::Instance::InstanceType
        AssociationPropertyMetadata:
          ZoneId: ${VSwitchZoneId}
      SystemDiskCategory:
        Type: String
        Label:
          en: System Disk Type
           
        Description:
          en: System Disk Type
           
        AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
        AssociationPropertyMetadata:
          ZoneId: ${VSwitchZoneId}
          InstanceType: ${InstanceType}
    Resources:
      OpsEcsInstance:
        Type: ALIYUN::ECS::InstanceGroup
        Properties:
          MaxAmount: 1
          HostName: OpsEcsInstance
          UserData:
            Fn::Sub:
              - |
                #!/bin/bash
                RootPassword=${RootPassword}
                ProdIP=${ProdIP}
                SSHConfig() {
                echo '[ ! -f /root/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -P "" -f ~/.ssh/id_rsa &>/dev/null' >> /tmp/auto_ssh.sh
                echo 'while read line;do' >> /tmp/auto_ssh.sh
                echo '        ip=`echo $line | cut -d " " -f1`' >> /tmp/auto_ssh.sh
                echo '        user_name=`echo $line | cut -d " " -f2`' >> /tmp/auto_ssh.sh
                echo '        pass_word=`echo $line | cut -d " " -f3`' >> /tmp/auto_ssh.sh
                echo 'expect <<EOF' >> /tmp/auto_ssh.sh
                echo '        spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $user_name@$ip' >> /tmp/auto_ssh.sh
                echo '        expect {' >> /tmp/auto_ssh.sh
                echo '                  "yes/no" { send "yes\n";exp_continue}' >> /tmp/auto_ssh.sh
                echo '                  "password" { send "$pass_word\n"}' >> /tmp/auto_ssh.sh
                echo '        }' >> /tmp/auto_ssh.sh
                echo '        expect eof' >> /tmp/auto_ssh.sh
                echo 'EOF' >> /tmp/auto_ssh.sh
                echo 'done < /tmp/host_ip.txt' >> /tmp/auto_ssh.sh
                }
                SetHostsConfig() {
                echo "`ifconfig eth0 | awk '/inet /{print $2}'` root ${RootPassword}" >> /tmp/host_ip.txt
                echo "${ProdIP} root ${RootPassword}" >> /tmp/host_ip.txt
                sh /tmp/auto_ssh.sh
                }
                main() {
                yum install -y expect
                SSHConfig
                SetHostsConfig
                rm -rf /tmp/host_ip.txt
                }
                main
              - ProdIP:
                  Fn::Select:
                    - '0'
                    - Fn::GetAtt:
                        - ProdEcsInstance
                        - PrivateIps
                RootPassword: Admin@123!
          VpcId:
            Ref: VpcId
          SecurityGroupId:
            Ref: SecurityGroupId
          VSwitchId:
            Ref: VSwitchId
          ImageId: centos_7
          AllocatePublicIP: false
          InstanceType:
            Ref: InstanceType
          SystemDiskSize: 40
          SystemDiskCategory:
            Ref: SystemDiskCategory
          Password: Admin@123!
      ProdEcsInstance:
        Type: ALIYUN::ECS::InstanceGroup
        Properties:
          MaxAmount: 1
          HostName: ProdEcsInstance
          SystemDiskCategory:
            Ref: SystemDiskCategory
          VpcId:
            Ref: VpcId
          SecurityGroupId:
            Ref: SecurityGroupId
          SystemDiskSize: 40
          ImageId: centos_7
          VSwitchId:
            Ref: VSwitchId
          Password: Admin@123!
          InstanceType:
            Ref: InstanceType
          AllocatePublicIP: false
    Outputs: {}                  
  • JSON format

    {
      "ROSTemplateFormatVersion": "2015-09-01",
      "Description": "Creates VPC ECS instance",
      "Parameters": {
        "VpcId": {
          "AssociationProperty": "ALIYUN::ECS::VPC::VPCId",
          "Type": "String",
          "Description": {
            "en": "Please search the ID starting with (vpc-xxx) from console-Virtual Private Cloud",
             
          },
          "Label": {
            "en": "VPC ID",
             
          }
        },
        "VSwitchZoneId": {
          "AssociationProperty": "ALIYUN::ECS::Instance:ZoneId",
          "Type": "String",
          "Description": {
             
            "en": "VSwitch Availability Zone"
          },
          "Label": {
             
            "en": "VSwitch Availability Zone"
          }
        },
        "VSwitchId": {
          "AssociationProperty": "ALIYUN::ECS::VSwitch::VSwitchId",
          "AssociationPropertyMetadata": {
            "VpcId": "${VpcId}",
            "ZoneId": "${VSwitchZoneId}"
          },
          "Type": "String",
          "Description": {
            "en": "Instance ID of existing business network switches, console-Virtual Private Cloud-VSwitches under query",
             
          },
          "Label": {
            "en": "VSwitch ID",
             
          }
        },
        "SecurityGroupId": {
          "Type": "String",
          "AssociationProperty": "ALIYUN::ECS::SecurityGroup::SecurityGroupId",
          "AssociationPropertyMetadata": {
            "VpcId": "${VpcId}"
          },
          "Description": {
            "en": "Please search the business security group ID starting with(sg-xxx)from console-ECS-Network & Security",
             
          },
          "Label": {
            "en": "Business Security Group ID",
             
          }
        },
        "InstanceType": {
          "Type": "String",
          "Description": {
             
            "en": "Fill in the specifications that can be used under the VSwitch availability zone."
          },
          "Label": {
             
            "en": "Instance Type"
          },
          "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
          "AssociationPropertyMetadata": {
            "ZoneId": "${VSwitchZoneId}"
          }
        },
        "SystemDiskCategory": {
          "Type": "String",
          "Label": {
            "en": "System Disk Type",
             
          },
          "Description": {
            "en": "System Disk Type",
             
          },
          "AssociationProperty": "ALIYUN::ECS::Disk::SystemDiskCategory",
          "AssociationPropertyMetadata": {
            "ZoneId": "${VSwitchZoneId}",
            "InstanceType": "${InstanceType}"
          }
        }
      },
      "Resources": {
        "OpsEcsInstance": {
          "Type": "ALIYUN::ECS::InstanceGroup",
          "Properties": {
            "MaxAmount": 1,
            "HostName": "OpsEcsInstance",
            "UserData": {
              "Fn::Sub": [
                "#!/bin/bash\nRootPassword=${RootPassword}\nProdIP=${ProdIP}\nSSHConfig() {\necho '[ ! -f /root/.ssh/id_rsa.pub ] && ssh-keygen -t rsa -P \"\" -f ~/.ssh/id_rsa &>/dev/null' >> /tmp/auto_ssh.sh\necho 'while read line;do' >> /tmp/auto_ssh.sh\necho '        ip=`echo $line | cut -d \" \" -f1`' >> /tmp/auto_ssh.sh\necho '        user_name=`echo $line | cut -d \" \" -f2`' >> /tmp/auto_ssh.sh\necho '        pass_word=`echo $line | cut -d \" \" -f3`' >> /tmp/auto_ssh.sh\necho 'expect <<EOF' >> /tmp/auto_ssh.sh\necho '        spawn ssh-copy-id -i /root/.ssh/id_rsa.pub $user_name@$ip' >> /tmp/auto_ssh.sh\necho '        expect {' >> /tmp/auto_ssh.sh\necho '                  \"yes/no\" { send \"yes\\n\";exp_continue}' >> /tmp/auto_ssh.sh\necho '                  \"password\" { send \"$pass_word\\n\"}' >> /tmp/auto_ssh.sh\necho '        }' >> /tmp/auto_ssh.sh\necho '        expect eof' >> /tmp/auto_ssh.sh\necho 'EOF' >> /tmp/auto_ssh.sh\necho 'done < /tmp/host_ip.txt' >> /tmp/auto_ssh.sh\n}\nSetHostsConfig() {\necho \"`ifconfig eth0 | awk '/inet /{print $2}'` root ${RootPassword}\" >> /tmp/host_ip.txt\necho \"${ProdIP} root ${RootPassword}\" >> /tmp/host_ip.txt\nsh /tmp/auto_ssh.sh\n}\nmain() {\nyum install -y expect\nSSHConfig\nSetHostsConfig\nrm -rf /tmp/host_ip.txt\n}\nmain\n",
                {
                  "ProdIP": {
                    "Fn::Select": [
                      "0",
                      {
                        "Fn::GetAtt": [
                          "ProdEcsInstance",
                          "PrivateIps"
                        ]
                      }
                    ]
                  },
                  "RootPassword": "Admin@123!"
                }
              ]
            },
            "VpcId": {
              "Ref": "VpcId"
            },
            "SecurityGroupId": {
              "Ref": "SecurityGroupId"
            },
            "VSwitchId": {
              "Ref": "VSwitchId"
            },
            "ImageId": "centos_7",
            "AllocatePublicIP": false,
            "InstanceType": {
              "Ref": "InstanceType"
            },
            "SystemDiskSize": 40,
            "SystemDiskCategory": {
              "Ref": "SystemDiskCategory"
            },
            "Password": "Admin@123!"
          }
        },
        "ProdEcsInstance": {
          "Type": "ALIYUN::ECS::InstanceGroup",
          "Properties": {
            "MaxAmount": 1,
            "HostName": "ProdEcsInstance",
            "SystemDiskCategory": {
              "Ref": "SystemDiskCategory"
            },
            "VpcId": {
              "Ref": "VpcId"
            },
            "SecurityGroupId": {
              "Ref": "SecurityGroupId"
            },
            "SystemDiskSize": 40,
            "ImageId": "centos_7",
            "VSwitchId": {
              "Ref": "VSwitchId"
            },
            "Password": "Admin@123!",
            "InstanceType": {
              "Ref": "InstanceType"
            },
            "AllocatePublicIP": false
          }
        }
      },
      "Outputs": {
      }
    }                    

For more examples, see InstanceGroup.json and InstanceGroup.yml. In the examples, the following resource types are used: ALIYUN::ECS::InstanceGroup, ALIYUN::ECS::InstanceClone, ALIYUN::ECS::Command, and ALIYUN::ECS::Invocation.