O recurso ALIYUN::ROS::Sleep atrasa as operações de criação, exclusão, atualização e rollback de recursos.
Sintaxe
{
"Type": "ALIYUN::ROS::Sleep",
"Properties": {
"DeleteDuration": Number,
"UpdateRollbackDuration": Number,
"UpdateDuration": Number,
"CreateDuration": Number,
"Triggers": Map
}
}
Propriedades
|
Nome da propriedade |
Tipo |
Obrigatório |
Atualização permitida |
Descrição |
Restrições |
|
DeleteDuration |
Number |
Não |
Sim |
Tempo de espera antes da exclusão do recurso. |
Valores válidos: 0 a 1800. Unidade: segundos. |
|
UpdateRollbackDuration |
Number |
Não |
Sim |
Tempo de espera antes do rollback durante uma atualização. |
Aplica-se apenas quando o stack passa por rollback e Triggers é alterado. Valores válidos: 0 a 1800. Unidade: segundos. |
|
UpdateDuration |
Number |
Não |
Sim |
Tempo de espera antes da atualização do recurso. |
Aplica-se apenas quando o stack é atualizado e Triggers é alterado. Valores válidos: 0 a 1800. Unidade: segundos. |
|
CreateDuration |
Number |
Não |
Não |
Tempo de espera antes da criação do recurso. |
Valores válidos: 0 a 1800. Unidade: segundos. |
|
Triggers |
Map |
Não |
Sim |
Controla o comportamento de espera para atualização e rollback. |
UpdateDuration e UpdateRollbackDuration aplicam-se apenas quando este parâmetro é alterado. |
Valores de retorno
Fn::GetAtt
Nenhum.
Exemplos
Este exemplo define os seguintes recursos:
Uma virtual private cloud (VPC)
Um vSwitch
Um grupo de segurança
Um atraso personalizado (Sleep)
Duas instâncias ECS (CenterServer e OtherServer)
O exemplo cria instâncias ECS em uma VPC:
A instância CenterServer implanta o Nginx e envia sua chave pública para a OtherServer, permitindo acesso SSH sem senha. Em seguida, a OtherServer acessa o serviço Nginx na CenterServer.
-
Defina CreateDuration como 60 segundos para garantir que a CenterServer conclua a implantação antes que a OtherServer tente acessá-la.
NotaA criação da instância termina antes da conclusão da instalação do aplicativo. O atraso compensa esse tempo de inicialização.
-
Formato
YAMLROSTemplateFormatVersion: '2015-09-01' Parameters: ZoneId: Type: String Label: Availability Zone AssociationProperty: ALIYUN::ECS::Instance::ZoneId Description: VSwitch available Zone Id, CreateDuration: Type: Number Description: The number of seconds to wait before resource creation. MinValue: 0 MaxValue: 1800 Default: 60 InstanceType: Type: String AssociationProperty: ALIYUN::ECS::Instance::InstanceType Label: en: Instance Type zh-cn: Instance Type Description: Fill in specifications that can be used under the VSwitch availability zone. AssociationPropertyMetadata: ZoneId: ${ZoneId} SystemDiskCategory: Type: String AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory AssociationPropertyMetadata: ZoneId: ${ZoneId} InstanceType: ${InstanceType} Label: System Disk Category InstancePassword: NoEcho: true Type: String Description: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers. Label: Instance Password MinLength: 8 MaxLength: 30 Resources: VPC: Type: ALIYUN::ECS::VPC Properties: CidrBlock: 10.0.0.0/16 VSwitch: Type: ALIYUN::ECS::VSwitch Properties: VpcId: Ref: VPC ZoneId: Ref: ZoneId CidrBlock: 10.0.1.0/24 SecurityGroup: Type: ALIYUN::ECS::SecurityGroup Properties: VpcId: Ref: VPC SecurityGroupIngress: - Priority: 1 PortRange: 80/80 NicType: intranet SourceCidrIp: 0.0.0.0/0 IpProtocol: tcp - Priority: 1 PortRange: 22/22 NicType: intranet SourceCidrIp: 100.104.0.0/16 IpProtocol: tcp WaitConditionHandle: Type: ALIYUN::ROS::WaitConditionHandle CenterServer: Type: ALIYUN::ECS::InstanceGroup Properties: InstanceName: ControlServer ImageId: centos_7.9 VpcId: Ref: VPC SecurityGroupId: Ref: SecurityGroup VSwitchId: Ref: VSwitch InstanceType: Ref: InstanceType Password: Ref: InstancePassword MaxAmount: 1 AllocatePublicIP: false SystemDiskSize: '40' InstanceChargeType: PostPaid SystemDiskCategory: Ref: SystemDiskCategory UserData: Fn::Replace: - ros-notify: Fn::GetAtt: - WaitConditionHandle - CurlCli - Fn::Join: - |+ - - '#!/bin/sh' - ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa - cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys - chmod 0600 ~/.ssh/authorized_keys - pub_key=`cat /root/.ssh/id_rsa.pub` - 'ros-notify -d "{\"status\" : \"SUCCESS\",\"id\" : \"ssh_pub_key\", \"data\" : \"$pub_key\"}" ' - yum install -y nginx - mkdir -p /data/nginx - echo "Hello World! This is service client ecs." > /data/nginx/index.html - 'echo ''server {'' >> /etc/nginx/conf.d/server.conf ' - 'echo ''listen 80;'' >> /etc/nginx/conf.d/server.conf ' - 'echo ''server_name _;'' >> /etc/nginx/conf.d/server.conf ' - 'echo ''index index.html;'' >> /etc/nginx/conf.d/server.conf ' - 'echo ''root /data/nginx;'' >> /etc/nginx/conf.d/server.conf ' - 'echo ''}'' >> /etc/nginx/conf.d/server.conf ' - systemctl stop nginx - systemctl start nginx - systemctl enable nginx WaitCondition: Type: ALIYUN::ROS::WaitCondition Properties: Count: 1 Handle: Ref: WaitConditionHandle Timeout: 1800 Sleep: Type: ALIYUN::ROS::Sleep DependsOn: WaitCondition Properties: CreateDuration: Ref: CreateDuration OtherServer: Type: ALIYUN::ECS::InstanceGroup DependsOn: Sleep Properties: InstanceName: OtherServer ImageId: centos_7.9 VpcId: Ref: VPC SecurityGroupId: Ref: SecurityGroup VSwitchId: Ref: VSwitch InstanceType: Ref: InstanceType Password: Ref: InstancePassword MaxAmount: 1 AllocatePublicIP: false SystemDiskSize: 40 InstanceChargeType: PostPaid SystemDiskCategory: Ref: SystemDiskCategory UserData: Fn::Join: - '' - - | #!/bin/sh - ssh_pub_key=' - Fn::GetAtt: - WaitCondition - Data - | ' - | yum install -y jq - | pub_key=`echo "$ssh_pub_key" | jq '.ssh_pub_key' | xargs echo ` - | echo "$pub_key" > /root/.ssh/authorized_keys - | chmod 600 /root/.ssh/authorized_keys - 'curl ' - Fn::Select: - '0' - Fn::GetAtt: - CenterServer - PrivateIps - | :80 -
Formato
JSON{ "ROSTemplateFormatVersion": "2015-09-01", "Parameters": { "ZoneId": { "Type": "String", "Label": "Availability Zone", "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId", "Description": "The ID of the availability zone for the vSwitch." }, "CreateDuration": { "Type": "Number", "Description": "The number of seconds to wait before resource creation.", "MinValue": 0, "MaxValue": 1800, "Default": 60 }, "InstanceType": { "Type": "String", "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType", "Label": { "en": "Instance Type", "zh-cn": "Instance Type" }, "Description": "The instance type. The instance type must be available in the availability zone of the specified vSwitch.", "AssociationPropertyMetadata": { "ZoneId": "${ZoneId}" } }, "SystemDiskCategory": { "Type": "String", "AssociationProperty": "ALIYUN::ECS::Disk::SystemDiskCategory", "AssociationPropertyMetadata": { "ZoneId": "${ZoneId}", "InstanceType": "${InstanceType}" }, "Label": "System Disk Category" }, "InstancePassword": { "NoEcho": true, "Type": "String", "Description": "The login password for the instance. The password must be 8 to 30 characters in length and contain uppercase letters, lowercase letters, and digits.", "Label": "Instance Password", "MinLength": 8, "MaxLength": 30 } }, "Resources": { "VPC": { "Type": "ALIYUN::ECS::VPC", "Properties": { "CidrBlock": "10.0.0.0/16" } }, "VSwitch": { "Type": "ALIYUN::ECS::VSwitch", "Properties": { "VpcId": { "Ref": "VPC" }, "ZoneId": { "Ref": "ZoneId" }, "CidrBlock": "10.0.1.0/24" } }, "SecurityGroup": { "Type": "ALIYUN::ECS::SecurityGroup", "Properties": { "VpcId": { "Ref": "VPC" }, "SecurityGroupIngress": [ { "Priority": 1, "PortRange": "80/80", "NicType": "intranet", "SourceCidrIp": "0.0.0.0/0", "IpProtocol": "tcp" }, { "Priority": 1, "PortRange": "22/22", "NicType": "intranet", "SourceCidrIp": "100.104.0.0/16", "IpProtocol": "tcp" } ] } }, "WaitConditionHandle": { "Type": "ALIYUN::ROS::WaitConditionHandle" }, "CenterServer": { "Type": "ALIYUN::ECS::InstanceGroup", "Properties": { "InstanceName": "ControlServer", "ImageId": "centos_7.9", "VpcId": { "Ref": "VPC" }, "SecurityGroupId": { "Ref": "SecurityGroup" }, "VSwitchId": { "Ref": "VSwitch" }, "InstanceType": { "Ref": "InstanceType" }, "Password": { "Ref": "InstancePassword" }, "MaxAmount": 1, "AllocatePublicIP": false, "SystemDiskSize": "40", "InstanceChargeType": "PostPaid", "SystemDiskCategory": { "Ref": "SystemDiskCategory" }, "UserData": { "Fn::Replace": [ { "ros-notify": { "Fn::GetAtt": [ "WaitConditionHandle", "CurlCli" ] } }, { "Fn::Join": [ "\n", [ "#!/bin/sh", "ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa", "cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys", "chmod 0600 ~/.ssh/authorized_keys", "pub_key=`cat /root/.ssh/id_rsa.pub`", "ros-notify -d \"{\\\"status\\\" : \\\"SUCCESS\\\",\\\"id\\\" : \\\"ssh_pub_key\\\", \\\"data\\\" : \\\"$pub_key\\\"}\" ", "yum install -y nginx", "mkdir -p /data/nginx", "echo \"Hello World! This is service client ecs.\" > /data/nginx/index.html", "echo 'server {' >> /etc/nginx/conf.d/server.conf ", "echo 'listen 80;' >> /etc/nginx/conf.d/server.conf ", "echo 'server_name _;' >> /etc/nginx/conf.d/server.conf ", "echo 'index index.html;' >> /etc/nginx/conf.d/server.conf ", "echo 'root /data/nginx;' >> /etc/nginx/conf.d/server.conf ", "echo '}' >> /etc/nginx/conf.d/server.conf ", "systemctl stop nginx", "systemctl start nginx", "systemctl enable nginx" ] ] } ] } } }, "WaitCondition": { "Type": "ALIYUN::ROS::WaitCondition", "Properties": { "Count": 1, "Handle": { "Ref": "WaitConditionHandle" }, "Timeout": 1800 } }, "Sleep": { "Type": "ALIYUN::ROS::Sleep", "DependsOn": "WaitCondition", "Properties": { "CreateDuration": { "Ref": "CreateDuration" } } }, "OtherServer": { "Type": "ALIYUN::ECS::InstanceGroup", "DependsOn": "Sleep", "Properties": { "InstanceName": "OtherServer", "ImageId": "centos_7.9", "VpcId": { "Ref": "VPC" }, "SecurityGroupId": { "Ref": "SecurityGroup" }, "VSwitchId": { "Ref": "VSwitch" }, "InstanceType": { "Ref": "InstanceType" }, "Password": { "Ref": "InstancePassword" }, "MaxAmount": 1, "AllocatePublicIP": false, "SystemDiskSize": 40, "InstanceChargeType": "PostPaid", "SystemDiskCategory": { "Ref": "SystemDiskCategory" }, "UserData": { "Fn::Join": [ "", [ "#!/bin/sh\n", "ssh_pub_key='", { "Fn::GetAtt": [ "WaitCondition", "Data" ] }, "'\n", "yum install -y jq\n", "pub_key=`echo \"$ssh_pub_key\" | jq '.ssh_pub_key' | xargs echo `\n", "echo \"$pub_key\" > /root/.ssh/authorized_keys\n", "chmod 600 /root/.ssh/authorized_keys\n", "curl ", { "Fn::Select": [ "0", { "Fn::GetAtt": [ "CenterServer", "PrivateIps" ] } ] }, ":80\n" ] ] } } } } }