ALIYUN::ROS::Sleep delays resource creation, deletion, update, and rollback operations.
Syntax
{
"Type": "ALIYUN::ROS::Sleep",
"Properties": {
"DeleteDuration": Number,
"UpdateRollbackDuration": Number,
"UpdateDuration": Number,
"CreateDuration": Number,
"Triggers": Map
}
}
Properties
| Property Name | Type | Required | Update allowed | Description | Constraints |
| DeleteDuration | Number | No | Yes | Wait duration before resource deletion. | Valid values: 0 to 1800. Unit: seconds. |
| UpdateRollbackDuration | Number | No | Yes | Wait duration before rollback during an update. | Takes effect only when the stack rolls back and Triggers changes. Valid values: 0 to 1800. Unit: seconds. |
| UpdateDuration | Number | No | Yes | Wait duration before resource update. | Takes effect only when the stack updates and Triggers changes. Valid values: 0 to 1800. Unit: seconds. |
| CreateDuration | Number | No | No | Wait duration before resource creation. | Valid values: 0 to 1800. Unit: seconds. |
| Triggers | Map | No | Yes | Triggers update and rollback wait behavior. | UpdateDuration and UpdateRollbackDuration take effect only when this parameter changes. |
Return values
Fn::GetAtt
None.
Examples
This example defines the following resources:
- A virtual private cloud (VPC)
- A vSwitch
- A security group
- A custom delay (Sleep)
- Two ECS instances (CenterServer and OtherServer)
The example creates ECS instances in a VPC:
- CenterServer deploys Nginx and sends its public key to OtherServer for passwordless SSH. OtherServer then accesses the Nginx service on CenterServer.
- CreateDuration is set to 60 seconds so CenterServer finishes deploying before OtherServer tries to access it.Note Instance creation completes before application installation finishes. The sleep accounts for this startup delay.
-
JSONformat{ "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" ] ] } } } } }
该文章对您有帮助吗?