Pelajari cara mengedit templat Resource Orchestration Service (ROS) untuk membuat grup instans Elastic Compute Service (ECS) dan menyambungkannya ke instans Classic Load Balancer (CLB).
Prasyarat
Pahami sintaks dan struktur templat. Untuk informasi selengkapnya, lihat Quick Start.
Skenario contoh
Buat grup instans ECS dalam virtual private cloud (VPC), terapkan layanan Nginx di dalam grup instans tersebut, lalu sambungkan grup instans ke instans CLB.

Catatan penggunaan
Lihat detail properti untuk setiap tipe resource. Untuk informasi selengkapnya, lihat View resource types.
Setiap tipe resource menentukan tipe, persyaratan, dan kebijakan pembaruan untuk propertinya. Properti wajib harus dideklarasikan dalam bagian `Properties` blok `Resources`. Properti opsional tidak perlu dideklarasikan. Jika suatu properti memperbolehkan pembaruan, Anda dapat memodifikasinya dalam templat baru lalu memperbarui stack untuk menerapkan perubahan tersebut. Jika tidak, properti tersebut tidak dapat diperbarui.
Edit templat
Temukan tipe resource yang diperlukan dalam indeks tipe resource. Untuk informasi selengkapnya, lihat Resource type index.
Skenario ini memerlukan resource berikut: VPC (ALIYUN::ECS::VPC), grup instans ECS (ALIYUN::ECS::InstanceGroup), instans Server Load Balancer (SLB) (ALIYUN::SLB::LoadBalancer), pendengar SLB (ALIYUN::SLB::Listener), alamat IP elastis (EIP) (ALIYUN::VPC::EIP), vSwitch (ALIYUN::ECS::VSwitch), dan security group (ALIYUN::ECS::SecurityGroup). Saat membuat grup instans ECS, Anda dapat menggunakan parameter UserData dari ALIYUN::ECS::InstanceGroup untuk menjalankan perintah inisialisasi. Anda juga dapat menggunakan resource wait condition (ALIYUN::ROS::WaitCondition) dan resource wait condition handle (ALIYUN::ROS::WaitConditionHandle) untuk mengontrol alur eksekusi dalam grup instans ECS.
Definisikan resource ini dalam bagian Resources templat.
Definisikan resource templat dan dependensinya
Definisikan resource jaringan dasar
Definisikan resource jaringan dasar seperti Vpc, VSwitch, dan EcsSecurityGroup.
-
Gunakan fungsi Ref dengan parameter pseudo ALIYUN::StackName untuk mengambil nama stack dan menggunakannya sebagai nilai properti resource. Misalnya, metode ini digunakan untuk properti
VpcNamepada resourceVpcdan propertiVSwitchNamepada resourceVSwitch. Untuk informasi selengkapnya, lihat Functions dan ALIYUN::StackName. -
Gunakan fungsi Ref untuk mengambil nilai kembali dari resource tertentu. Misalnya, `Ref: Vpc` dalam resource
VSwitchmengambil nilai kembaliVpcIddari resourceVpc. Nilai kembali biasanya merupakan ID resource. Untuk informasi selengkapnya, lihat Functions.
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock: 192.168.0.0/16
VpcName:
Ref: ALIYUN::StackName
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VSwitchName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId
CidrBlock: 192.168.0.0/24
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
Definisikan resource instans SLB dan EIP
Definisikan instans SLB Slb, pendengar SLB SlbListener, dan resource EIP EipSlbAddress.
Fungsi Fn::Sub menggabungkan parameter pseudo ALIYUN::StackName ke dalam string baru untuk digunakan sebagai nilai properti resource. Untuk informasi selengkapnya, lihat ALIYUN::StackName.
Resources:
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName:
Fn::Sub: slb-${ALIYUN::StackName}
PayType:
Ref: PayType
PricingCycle:
Ref: PayPeriodUnit
Duration:
Ref: PayPeriod
AddressType: intranet
LoadBalancerSpec:
Ref: LoadBalancerSpec
AutoPay: true
SlbListener:
DependsOn:
- Slb
Type: ALIYUN::SLB::Listener
Properties:
Persistence:
CookieTimeout: 60
StickySession: 'on'
PersistenceTimeout: 180
XForwardedFor: 'off'
StickySessionType: insert
ListenerPort: 80
Bandwidth: -1
HealthCheck:
HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
HealthCheckType: tcp
UnhealthyThreshold: 3
Timeout: 5
HealthyThreshold: 3
Port: 80
URI: /
Interval: 2
LoadBalancerId:
Ref: Slb
BackendServerPort: 80
Protocol: tcp
EipSlbAddress:
Type: ALIYUN::VPC::EIP
Properties:
Name:
Ref: ALIYUN::StackName
InternetChargeType: PayByTraffic
Bandwidth:
Ref: Bandwidth
Definisikan grup instans ECS, resource wait condition, dan resource wait condition handle
Definisikan grup instans ECS EcsInstanceGroup, resource wait condition WaitCondition, dan resource wait condition handle WaitConditionHandle.
-
Gunakan fungsi Fn::GetAtt untuk mengambil nilai atribut dari resource dalam templat. Misalnya, Anda dapat mengambil nilai kembali
CurlClidari resourceWaitConditionHandle. Untuk informasi selengkapnya, lihat Functions. -
Gunakan fungsi Fn::Sub untuk menyusun string perintah dan mengganti variabel dalam string input dengan nilai yang ditentukan. Misalnya, dalam properti UserData resource
EcsInstanceGroup, ${CurlCli} diganti dengan nilai CurlCli. Untuk informasi selengkapnya, lihat Functions. -
Kombinasi resource berikut mengontrol proses inisialisasi dalam instans ECS.
-
Buat resource wait condition (ALIYUN::ROS::WaitCondition).
-
Buat resource wait condition handle (ALIYUN::ROS::WaitConditionHandle).
-
Dalam UserData instans ECS, jalankan skrip dan kirim sinyal. Misalnya, konten UserData dalam resource
EcsInstanceGroupberisi skrip inisialisasi untuk instans ECS. Setelah skrip berhasil dijalankan, skrip tersebut mengirim callback ke resourceWaitConditionHandle, sehingga mengakhiri status tunggu resourceWaitCondition.
-
Resources:
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 300
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: EcsSecurityGroup
VSwitchId:
Ref: VSwitch
MaxAmount: 2
ImageId: centos_7
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: false
UserData:
Fn::Sub:
- |
#!/bin/bash
# Mount the disk to /disk1
cat >> /root/InitDataDisk.sh << EOF
#!/bin/bash
echo "p
n
p
w
" | fdisk -u /dev/vdb
EOF
/bin/bash /root/InitDataDisk.sh
rm -f /root/InitDataDisk.sh
rm -f InitDataDisk.sh
mkfs -t ext4 /dev/vdb1
cp /etc/fstab /etc/fstab.bak
mkdir /disk1
echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\\\"//g'` /disk1 ext4 defaults 0 0 >> /etc/fstab
mount -a
# Configure the installation script
yum install -y nginx
# Configure the startup script
systemctl start nginx.service
# Send a success signal to WaitConditionHandle to end the wait of WaitCondition.
${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
- CurlCli:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
Definisikan dependensi untuk grup instans ECS, instans SLB, dan lampiran server backend
Definisikan grup instans ECS EcsInstanceGroup, instans SLB Slb, dan lampiran server backend SlbBackendServerAttachment.
-
Gunakan
SlbBackendServerAttachmentuntuk menyambungkan grup instans ECS ke instans CLB. Untuk informasi selengkapnya, lihat ALIYUN::SLB::BackendServerAttachment.Dalam ALIYUN::SLB::BackendServerAttachment, jika Anda tidak menentukan nilai untuk
BackendServerWeightList, bobot semua instans ECS dalamBackendServerListsecara default adalah 100. JikaBackendServerWeightListberisi entri lebih sedikit daripadaBackendServerList, nilai bobot terakhir dalamBackendServerWeightListditerapkan ke semua instans ECS yang tersisa dalamBackendServerList. -
Gunakan properti DependsOn untuk menentukan bahwa suatu resource dibuat hanya setelah resource lain dibuat. Untuk informasi selengkapnya, lihat DependsOn.
-
Gunakan fungsi Fn::GetAtt untuk mengambil nilai properti output resource. Misalnya, Anda dapat mengambil
InstanceIdsdari resourceEcsInstanceGroup. Untuk informasi selengkapnya, lihat Functions.
Resources:
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: EcsSecurityGroup
VSwitchId:
Ref: VSwitch
MaxAmount: 2
ImageId: centos_7
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: false
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName:
Fn::Sub: slb-${ALIYUN::StackName}
PayType:
Ref: PayType
PricingCycle:
Ref: PayPeriodUnit
Duration:
Ref: PayPeriod
AddressType: intranet
LoadBalancerSpec:
Ref: LoadBalancerSpec
AutoPay: true
SlbBackendServerAttachment:
DependsOn:
- EcsInstanceGroup
- Slb
Type: ALIYUN::SLB::BackendServerAttachment
Properties:
BackendServerList:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
LoadBalancerId:
Ref: Slb
BackendServerWeightList:
- 100
- 50
Templat contoh lengkap
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Create a new VPC and vSwitch, create one CLB instance, two ECS instances, and attach all ECS instances to the CLB instance.
zh-cn: Create a new VPC and vSwitch, create one CLB instance, two ECS instances, and attach all ECS instances to the CLB instance.
Parameters:
ZoneId:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
Label:
en: vSwitch Zone
zh-cn: vSwitch Zone
VpcCidrBlock:
Default: 192.168.0.0/16
Label:
zh-cn: VPC CIDR Block
en: VPC CIDR Block
Type: String
Description:
zh-cn: The CIDR block for the new VPC. The following CIDR blocks are recommended<br/><font color='green'>[10.0.0.0/8]</font><br><font color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
en: The CIDR block for the new VPC. The following CIDR blocks are recommended<br><font color='green'>[10.0.0.0/8]</font><br><font color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
VSwitchCidrBlock:
Default: 192.168.0.0/24
Type: String
Description:
zh-cn: Must be a subnet of the VPC and not used by other vSwitches.
en: Must be a subnet of the VPC and not used by other vSwitches.
Label:
zh-cn: vSwitch CIDR Block
en: vSwitch CIDR Block
EcsInstanceType:
Type: String
Label:
en: Instance Type
zh-cn: Instance Type
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceChargeType: ${InstanceChargeType}
SystemDiskCategory:
Type: String
Description:
en: '<font color=''blue''><b>Valid values:</font><br/>[cloud_efficiency: <font color=''green''>ultra disk</font>]<br>[cloud_ssd: <font color=''green''>standard SSD</font>]<br>[cloud_essd: <font color=''green''>enterprise SSD</font>]<br>[cloud: <font color=''green''>basic disk</font>]<br>[ephemeral_ssd: <font color=''green''>local SSD</font>]'
zh-cn: '<font color=''blue''><b>Valid values:</font><br/>[cloud_efficiency: <font color=''green''>ultra disk</font>]<br>[cloud_ssd: <font color=''green''>standard SSD</font>]<br>[cloud_essd: <font color=''green''>enterprise SSD</font>]<br>[cloud: <font color=''green''>basic disk</font>]<br>[ephemeral_ssd: <font color=''green''>local SSD</font>]'
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${EcsInstanceType}
Label:
en: System Disk Type
zh-cn: System Disk Type
SystemDiskSize:
Default: 40
Type: Number
Description:
zh-cn: Ukuran disk sistem. Nilai valid: 40 hingga 500. Satuan: GB.
Label:
zh-cn: System Disk Size
en: System Disk Size
DataDiskCategory:
AssociationProperty: ALIYUN::ECS::Disk::DataDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${EcsInstanceType}
Type: String
Description:
zh-cn: '<font color=''blue''><b>Valid values:</font><br/>[cloud_efficiency: <font color=''green''>ultra disk</font>]<br>[cloud_ssd: <font color=''green''>standard SSD</font>]<br>[cloud_essd: <font color=''green''>enterprise SSD</font>]<br>[cloud: <font color=''green''>basic disk</font>]'
en: '<font color=''blue''><b>Valid values:</font><br/>[cloud_efficiency: <font color=''green''>ultra disk</font>]<br>[cloud_ssd: <font color=''green''>standard SSD</font>]<br>[cloud_essd: <font color=''green''>enterprise SSD</font>]<br>[cloud: <font color=''green''>basic disk</font>]'
Label:
zh-cn: Data Disk Type
en: Data Disk Type
DataDiskSize:
Description:
zh-cn: Ukuran disk data untuk instans ECS. Satuan: GiB. Nilai valid: 20 hingga 32768.
Default: 100
MaxValue: 32768
MinValue: 20
Label:
zh-cn: Data Disk Size
en: Data Disk Size
Type: Number
InstancePassword:
NoEcho: true
Type: String
Description:
en: The logon password for the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
zh-cn: The logon password for the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
Label:
en: Instance Password
zh-cn: Instance Password
ConstraintDescription:
en: The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
zh-cn: The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
MinLength: 8
MaxLength: 30
AssociationProperty: ALIYUN::ECS::Instance::Password
PayType:
Type: String
Label:
en: Billing Method
zh-cn: Billing Method
Default: PostPaid
AllowedValues:
- PostPaid
- PrePaid
AssociationProperty: ChargeType
AssociationPropertyMetadata:
LocaleKey: InstanceChargeType
PayPeriodUnit:
Type: String
Description:
en: The subscription duration unit. Valid values: Week and Month. The default value is Month.<br><b><font color='red'>This parameter is valid only when the billing method is Subscription.</font>
zh-cn: The subscription duration unit. Valid values: Week and Month. The default value is Month.<br/><b><font color='red'>This parameter is valid only when the billing method is Subscription.</font>
Label:
en: Subscription Duration Unit
zh-cn: Subscription Duration Unit
Default: Month
AllowedValues:
- Month
- Year
AssociationProperty: PayPeriodUnit
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
PayPeriod:
Type: Number
Label:
en: Subscription Duration
zh-cn: Subscription Duration
Default: 1
AllowedValues:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
AssociationProperty: PayPeriod
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
LoadBalancerSpec:
Type: String
AssociationProperty: ALIYUN::SLB::Instance::InstanceType
Label:
en: SLB Instance Edition
zh-cn: SLB Instance Edition
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
Bandwidth:
Description:
zh-cn: Nilai valid: 0 hingga 1000. Satuan: Mbps.
en: 'Valid values: 0 to 1000. Unit: Mbps.'
Default: 10
MaxValue: 1000
Label:
zh-cn: EIP Bandwidth for SLB
en: EIP Bandwidth for SLB
MinValue: 1
Type: Number
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: ALIYUN::StackName
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VSwitchName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId
CidrBlock:
Ref: VSwitchCidrBlock
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 300
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: EcsSecurityGroup
VSwitchId:
Ref: VSwitch
MaxAmount: 2
ImageId: centos_7
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: false
UserData:
Fn::Sub:
- |
#!/bin/bash
# Mount the disk to /disk1
cat >> /root/InitDataDisk.sh << EOF
#!/bin/bash
echo "p
n
p
w
" | fdisk -u /dev/vdb
EOF
/bin/bash /root/InitDataDisk.sh
rm -f /root/InitDataDisk.sh
rm -f InitDataDisk.sh
mkfs -t ext4 /dev/vdb1
cp /etc/fstab /etc/fstab.bak
mkdir /disk1
echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\\\"//g'` /disk1 ext4 defaults 0 0 >> /etc/fstab
mount -a
# Configure the installation script
yum install -y nginx
# Configure the startup script
systemctl start nginx.service
# Send a success signal to WaitConditionHandle to end the wait of WaitCondition.
${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
- CurlCli:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName:
Fn::Sub: slb-${ALIYUN::StackName}
PayType:
Ref: PayType
PricingCycle:
Ref: PayPeriodUnit
Duration:
Ref: PayPeriod
AddressType: intranet
LoadBalancerSpec:
Ref: LoadBalancerSpec
AutoPay: true
EipSlbAddress:
Type: ALIYUN::VPC::EIP
Properties:
Name:
Ref: ALIYUN::StackName
InternetChargeType: PayByTraffic
Bandwidth:
Ref: Bandwidth
EipSlbAddressAssociation:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Ref: Slb
AllocationId:
Ref: EipSlbAddress
SlbBackendServerAttachment:
DependsOn:
- EcsInstanceGroup
Type: ALIYUN::SLB::BackendServerAttachment
Properties:
BackendServerList:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
LoadBalancerId:
Ref: Slb
BackendServerWeightList:
- 100
- 100
SlbListener:
DependsOn:
- Slb
Type: ALIYUN::SLB::Listener
Properties:
Persistence:
CookieTimeout: 60
StickySession: 'on'
PersistenceTimeout: 180
XForwardedFor: 'off'
StickySessionType: insert
ListenerPort: 80
Bandwidth: -1
HealthCheck:
HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
HealthCheckType: tcp
UnhealthyThreshold: 3
Timeout: 5
HealthyThreshold: 3
Port: 80
URI: /
Interval: 2
LoadBalancerId:
Ref: Slb
BackendServerPort: 80
Protocol: tcp
Outputs:
Endpoint:
Description:
zh-cn: Alamat IP publik.
en: The public IP address.
Value:
Fn::Sub:
- http://${ServerAddress}
- ServerAddress:
Fn::GetAtt:
- EipSlbAddress
- EipAddress<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
Tambahkan grup parameter dan dapatkan konfigurasi parameter secara dinamis
Properti InstanceType dan SystemDiskCategory resource EcsInstanceGroup serta properti LoadBalancerSpec resource Slb mereferensikan parameter. Saat membuat stack di wilayah berbeda, Anda harus memberikan nilai berbeda untuk properti ini pada setiap penerapan.
Tambahkan bagian Parameters ke templat agar lebih fleksibel dan dapat digunakan kembali.
Tambahkan grup parameter
Gunakan bagian Metadata untuk mengelompokkan parameter yang didefinisikan dalam bagian Parameters dan menentukan label untuk grup parameter tersebut.
Setelah mendefinisikan resource dan parameter templat, kelompokkan parameter berdasarkan resource yang sesuai.
Tabel berikut menunjukkan cara mengelompokkan resource untuk contoh ini.
|
Kategori parameter |
Nama resource |
Nama parameter |
|
Konfigurasi jaringan dasar |
|
|
|
Konfigurasi SLB |
|
|
|
Konfigurasi ECS |
|
|
Dapatkan konfigurasi parameter secara dinamis
Ambil EcsInstanceType sebagai contoh. Untuk menetapkan kondisi filter dan memilih konfigurasi secara dinamis di Konsol ROS, temukan nilai AssociationProperty yang didukungnya. Berdasarkan tipe resource ALIYUN::ECS::InstanceGroup, nilainya adalah ALIYUN::ECS::Instance::InstanceType. Kemudian, kueri nilai AssociationPropertyMetadata menggunakan kondisi filter seperti ZoneId dan InstanceChargeType. Untuk informasi selengkapnya, lihat AssociationProperty and AssociationPropertyMetadata.
Templat contoh lengkap
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Create one CLB instance and two ECS instances in a VPC and vSwitch, and attach all ECS instances to the CLB instance.
zh-cn: Create one CLB instance and two ECS instances in a VPC and vSwitch, and attach all ECS instances to the CLB instance.
Parameters:
ZoneId:
Type: String
AssociationProperty: ALIYUN::ECS::Instance::ZoneId
Label:
en: vSwitch Zone
zh-cn: vSwitch Zone
VpcCidrBlock:
Default: 192.168.0.0/16
Label:
zh-cn: VPC CIDR Block
en: VPC CIDR Block
Type: String
Description:
zh-cn: The CIDR block for the new VPC. The following CIDR blocks are recommended<br/><font color='green'>[10.0.0.0/8]</font><br><font color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
en: The CIDR block for the new VPC. The following CIDR blocks are recommended<br><font color='green'>[10.0.0.0/8]</font><br><font color='green'>[172.16.0.0/12]</font><br><font color='green'>[192.168.0.0/16]</font>
VSwitchCidrBlock:
Default: 192.168.0.0/24
Type: String
Description:
zh-cn: Must be a subnet of the VPC and not used by other vSwitches.
en: Must be a subnet of the VPC and not used by other vSwitches.
Label:
zh-cn: vSwitch CIDR Block
en: vSwitch CIDR Block
EcsInstanceType:
Type: String
Label:
en: Instance Type
zh-cn: Instance Type
AssociationProperty: ALIYUN::ECS::Instance::InstanceType
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceChargeType: ${InstanceChargeType}
SystemDiskCategory:
Type: String
Description:
en: '<font color=''blue''><b>Valid values:</font><br/>[cloud_efficiency: <font color=''green''>ultra disk</font>]<br>[cloud_ssd: <font color=''green''>standard SSD</font>]<br>[cloud_essd: <font color=''green''>enterprise SSD</font>]<br>[cloud: <font color=''green''>basic disk</font>]<br>[ephemeral_ssd: <font color=''green''>local SSD</font>]'
zh-cn: '<font color=''blue''><b>Valid values:</font><br/>[cloud_efficiency: <font color=''green''>ultra disk</font>]<br>[cloud_ssd: <font color=''green''>standard SSD</font>]<br>[cloud_essd: <font color=''green''>enterprise SSD</font>]<br>[cloud: <font color=''green''>basic disk</font>]<br>[ephemeral_ssd: <font color=''green''>local SSD</font>]'
AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${EcsInstanceType}
Label:
en: System Disk Type
zh-cn: System Disk Type
SystemDiskSize:
Default: 40
Type: Number
Description:
zh-cn: Ukuran disk sistem. Nilai valid: 40 hingga 500. Satuan: GB.
en: 'The size of the system disk. Valid values: 40 to 500. Unit: GB.'
Label:
zh-cn: System Disk Size
en: System Disk Size
DataDiskCategory:
AssociationProperty: ALIYUN::ECS::Disk::DataDiskCategory
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
InstanceType: ${EcsInstanceType}
Type: String
Description:
zh-cn: '<font color=''blue''><b>Valid values:</font><br/>[cloud_efficiency: <font color=''green''>ultra disk</font>]<br>[cloud_ssd: <font color=''green''>standard SSD</font>]<br>[cloud_essd: <font color=''green''>enterprise SSD</font>]<br>[cloud: <font color=''green''>basic disk</font>]'
en: '<font color=''blue''><b>Valid values:</font><br/>[cloud_efficiency: <font color=''green''>ultra disk</font>]<br>[cloud_ssd: <font color=''green''>standard SSD</font>]<br>[cloud_essd: <font color=''green''>enterprise SSD</font>]<br>[cloud: <font color=''green''>basic disk</font>]'
Label:
zh-cn: Data Disk Type
en: Data Disk Type
DataDiskSize:
Description:
zh-cn: Ukuran disk data untuk instans ECS. Satuan: GiB. Nilai valid: 20 hingga 32768.
en: 'The size of the data disk for the ECS instance. Unit: GiB. Valid values: 20 to 32768.'
Default: 100
MaxValue: 32768
MinValue: 20
Label:
zh-cn: Data Disk Size
en: Data Disk Size
Type: Number
InstancePassword:
NoEcho: true
Type: String
Description:
en: The logon password for the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
zh-cn: The logon password for the server. The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
AllowedPattern: '[0-9A-Za-z\_\-\&:;''<>,=%`~!@#\(\)\$\^\*\+\|\{\}\[\]\.\?\/]+$'
Label:
en: Instance Password
zh-cn: Instance Password
ConstraintDescription:
en: The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
zh-cn: The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters from the following set: ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/.
MinLength: 8
MaxLength: 30
AssociationProperty: ALIYUN::ECS::Instance::Password
PayType:
Type: String
Label:
en: Billing Method
zh-cn: Billing Method
Default: PostPaid
AllowedValues:
- PostPaid
- PrePaid
AssociationProperty: ChargeType
AssociationPropertyMetadata:
LocaleKey: InstanceChargeType
PayPeriodUnit:
Type: String
Description:
en: The subscription duration unit. Valid values: Week and Month. The default value is Month.<br><b><font color='red'>This parameter is valid only when the billing method is Subscription.</font>
zh-cn: The subscription duration unit. Valid values: Week and Month. The default value is Month.<br/><b><font color='red'>This parameter is valid only when the billing method is Subscription.</font>
Label:
en: Subscription Duration Unit
zh-cn: Subscription Duration Unit
Default: Month
AllowedValues:
- Month
- Year
AssociationProperty: PayPeriodUnit
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
PayPeriod:
Type: Number
Label:
en: Subscription Duration
zh-cn: Subscription Duration
Default: 1
AllowedValues:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
AssociationProperty: PayPeriod
AssociationPropertyMetadata:
Visible:
Condition:
Fn::Not:
Fn::Equals:
- ${PayType}
- PostPaid
LoadBalancerSpec:
Type: String
AssociationProperty: ALIYUN::SLB::Instance::InstanceType
Label:
en: SLB Instance Edition
zh-cn: SLB Instance Edition
AssociationPropertyMetadata:
ZoneId: ${ZoneId}
Bandwidth:
Description:
zh-cn: Nilai valid: 0 hingga 1000. Satuan: Mbps.
en: 'Valid values: 0 to 1000. Unit: Mbps.'
Default: 10
MaxValue: 1000
Label:
zh-cn: EIP Bandwidth for SLB
en: EIP Bandwidth for SLB
MinValue: 1
Type: Number
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
CidrBlock:
Ref: VpcCidrBlock
VpcName:
Ref: ALIYUN::StackName
VSwitch:
Type: ALIYUN::ECS::VSwitch
Properties:
VSwitchName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
ZoneId:
Ref: ZoneId
CidrBlock:
Ref: VSwitchCidrBlock
EcsSecurityGroup:
Type: ALIYUN::ECS::SecurityGroup
Properties:
SecurityGroupName:
Ref: ALIYUN::StackName
VpcId:
Ref: Vpc
SecurityGroupIngress:
- PortRange: 80/80
Priority: 1
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: internet
SecurityGroupEgress:
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: internet
- PortRange: '-1/-1'
Priority: 1
IpProtocol: all
DestCidrIp: 0.0.0.0/0
NicType: intranet
WaitCondition:
Type: ALIYUN::ROS::WaitCondition
Properties:
Count: 1
Handle:
Ref: WaitConditionHandle
Timeout: 300
WaitConditionHandle:
Type: ALIYUN::ROS::WaitConditionHandle
EcsInstanceGroup:
Type: ALIYUN::ECS::InstanceGroup
Properties:
InstanceChargeType:
Ref: PayType
PeriodUnit:
Ref: PayPeriodUnit
Period:
Ref: PayPeriod
IoOptimized: optimized
SystemDiskCategory:
Ref: SystemDiskCategory
SystemDiskSize:
Ref: SystemDiskSize
DiskMappings:
- Category:
Ref: DataDiskCategory
Size:
Ref: DataDiskSize
VpcId:
Ref: Vpc
SecurityGroupId:
Ref: EcsSecurityGroup
VSwitchId:
Ref: VSwitch
MaxAmount: 2
ImageId: centos_7
InstanceType:
Ref: EcsInstanceType
Password:
Ref: InstancePassword
AllocatePublicIP: false
UserData:
Fn::Sub:
- |
#!/bin/bash
# Mount the disk to /disk1
cat >> /root/InitDataDisk.sh << EOF
#!/bin/bash
echo "p
n
p
w
" | fdisk -u /dev/vdb
EOF
/bin/bash /root/InitDataDisk.sh
rm -f /root/InitDataDisk.sh
rm -f InitDataDisk.sh
mkfs -t ext4 /dev/vdb1
cp /etc/fstab /etc/fstab.bak
mkdir /disk1
echo `blkid /dev/vdb1 | awk '{print $2}' | sed 's/\\\"//g'` /disk1 ext4 defaults 0 0 >> /etc/fstab
mount -a
# Configure the installation script
yum install -y nginx
# Configure the startup script
systemctl start nginx.service
# Send a success signal to WaitConditionHandle to end the wait of WaitCondition.
${CurlCli} -d "{\"Data\" : \"Success\", \"status\" : \"SUCCESS\"}"
- CurlCli:
Fn::GetAtt:
- WaitConditionHandle
- CurlCli
Slb:
Type: ALIYUN::SLB::LoadBalancer
Properties:
VpcId:
Ref: Vpc
VSwitchId:
Ref: VSwitch
LoadBalancerName:
Fn::Sub: slb-${ALIYUN::StackName}
PayType:
Ref: PayType
PricingCycle:
Ref: PayPeriodUnit
Duration:
Ref: PayPeriod
AddressType: intranet
LoadBalancerSpec:
Ref: LoadBalancerSpec
AutoPay: true
EipSlbAddress:
Type: ALIYUN::VPC::EIP
Properties:
Name:
Ref: ALIYUN::StackName
InternetChargeType: PayByTraffic
Bandwidth:
Ref: Bandwidth
EipSlbAddressAssociation:
Type: ALIYUN::VPC::EIPAssociation
Properties:
InstanceId:
Ref: Slb
AllocationId:
Ref: EipSlbAddress
SlbBackendServerAttachment:
DependsOn:
- EcsInstanceGroup
Type: ALIYUN::SLB::BackendServerAttachment
Properties:
BackendServerList:
Fn::GetAtt:
- EcsInstanceGroup
- InstanceIds
LoadBalancerId:
Ref: Slb
BackendServerWeightList:
- 100
- 50
SlbListener:
DependsOn:
- Slb
Type: ALIYUN::SLB::Listener
Properties:
Persistence:
CookieTimeout: 60
StickySession: 'on'
PersistenceTimeout: 180
XForwardedFor: 'off'
StickySessionType: insert
ListenerPort: 80
Bandwidth: -1
HealthCheck:
HttpCode: http_2xx,http_3xx,http_4xx,http_5xx
HealthCheckType: tcp
UnhealthyThreshold: 3
Timeout: 5
HealthyThreshold: 3
Port: 80
URI: /
Interval: 2
LoadBalancerId:
Ref: Slb
BackendServerPort: 80
Protocol: tcp
Outputs:
Endpoint:
Description:
zh-cn: Alamat IP publik
en: The public IP address
Value:
Fn::Sub:
- http://${ServerAddress}
- ServerAddress:
Fn::GetAtt:
- EipSlbAddress
- EipAddress
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- ZoneId
- VpcCidrBlock
- VSwitchCidrBlock
Label:
default:
zh-cn: Konfigurasi Jaringan Dasar
en: Basic Network Configuration
- Parameters:
- PayType
- PayPeriodUnit
- PayPeriod
Label:
default:
en: Billing Method Configuration
zh-cn: Konfigurasi Metode Penagihan
- Parameters:
- EcsInstanceType
- SystemDiskCategory
- SystemDiskSize
- DataDiskCategory
- DataDiskSize
- InstancePassword
Label:
default:
en: ECS Instance Configuration
zh-cn: Konfigurasi Instans ECS
- Parameters:
- LoadBalancerSpec
- Bandwidth
Label:
default:
en: SLB Configuration
zh-cn: Konfigurasi SLB
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>