ALIYUN::ROS::WaitConditionHandle

更新时间:
复制 MD 格式

ALIYUN::ROS::WaitConditionHandle receives signals and works with ALIYUN::ROS::WaitCondition to control stack execution flow. For example, when you create an ECS instance, a signal is sent during user data execution.

Syntax

{
  "Type": "ALIYUN::ROS::WaitConditionHandle",
  "Properties": {
    "Mode": String,
    "Count": Integer
  }
}

Properties

Property

Type

Required

Editable

Description

Constraint

Mode

String

No

Yes

The signal deletion mode used before resource updates.

Valid values:

  • Increment: Deletes all existing signals before the resource update.

    Note

    During updates, the expected signal count equals the Count value in ALIYUN::ROS::WaitCondition.

  • Full: Deletes existing signals before the resource update only if the Count property takes effect.

    Note

    During updates, the expected signal count = Count value in ALIYUN::ROS::WaitCondition - remaining signals after deletion.

Count

Integer

No

Yes

When Mode is set to Full, signals with integer IDs greater than the Count value are deleted before the resource update.

Default value: -1.

Count takes effect when:

  • Mode is set to Full.

  • Count is 0 or greater.

When Count takes effect, signals with integer IDs greater than the Count value are deleted before the update. If any signal IDs are non-integers, the update fails.

Note

For elastic scaling via stack updates, set Count in ALIYUN::ROS::WaitConditionHandle to match the Count value in ALIYUN::ROS::WaitCondition.

Return values

Fn::GetAtt

  • CurlCli: the cURL command generated by ALIYUN::ROS::WaitConditionHandle. Run this command to send user data execution results to ROS.

  • WindowsCurlCli: the cURL command prefix for Windows. Install curl.exe and add it to PATH before use. Append -d "{\"status\": \" SUCCESS \"} for success or -d "{\"status\": \" FAILURE \"} for failure.

  • PowerShellCurlCli: the cURL command prefix for PowerShell 3.0 or later. Check your version with $PSVersionTable.PSVersion. Append -Body '{"status": " SUCCESS "} for success or -Body '{"status": " FAILURE "} for failure.

  • Headers: the HTTP POST request header for sending execution status signals to your program.

  • URL: the HTTP POST request URL for sending execution status signals to your program.

Note
  • Use the id parameter (STRING) in the request body of CurlCli, WindowsCurlCli, or PowerShellCurlCli to specify a signal ID.

    Example: -d "{\"status\": \" SUCCESS \", \"id\": \"test\".

    Signals with the same ID overwrite previous ones.

    If no signal ID is specified, ROS auto-assigns an integer ID equal to the existing signal count + 1.

  • Use the reason parameter (STRING) to specify why execution succeeded or failed. The value appears in the stack event that records the signal notification.

    Example: -d "{\"status\": \" SUCCESS \", \"reason\": \"nginx is installed successfully.\"}".

    The reason value is recorded in the corresponding stack event.

  • Use the data parameter (STRING) to attach data to the signal. Retrieve this data through the Data, ErrorData, or JoinedErrorData return values of ALIYUN::ROS::WaitCondition.

    Example: -d "{\"id\" : \"ssh_pub_key\", \"data\" : \"$pub_key\"}".

  • The status parameter specifies the signal type: SUCCESS, FAILURE, or WARNING. Signal types determine the resource operation result, in descending priority:

    • A FAILURE signal causes the resource operation to fail.

    • If fewer signals than the Count value are received within the timeout period, the operation times out.

    • If the signal count meets or exceeds Count but all signals are WARNING, the operation fails.

    • Otherwise, the operation succeeds.

Examples

  • YAML format

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      InstanceId:
        Type: String
        AssociationProperty: ALIYUN::ECS::Instance::InstanceId
    Resources:
      InstallNginx:
        Type: 'ALIYUN::ECS::RunCommand'
        Properties:
          Type: RunShellScript
          CommandContent:
            Fn::Sub: |
                #!/bin/sh
                yum install -y nginx
                systemctl restart nginx
                if [[ $? -eq 0 ]];
                then
                ${InstallNginxWaitConditionHandle.CurlCli} --data-binary "{\"status\": \"SUCCESS\", \"data\": \"Nginx is installed successfully.\"}"
                else
                ${InstallNginxWaitConditionHandle.CurlCli} --data-binary "{\"status\": \"FAILURE\", \"reason\": \"Failed to install and start nginx.\"}"
                fi
          Name: InstallNginxScript
          InstanceIds:
            - Ref:
                InstanceId
          Timeout: 60
      InstallNginxWaitConditionHandle:
        Type: 'ALIYUN::ROS::WaitConditionHandle'
      InstallNginxWaitCondition:
        Type: 'ALIYUN::ROS::WaitCondition'
        Properties:
          Handle:
            Ref: InstallNginxWaitConditionHandle
          Timeout: 60
    Outputs:
      InstallNginxData:
        Description: Received the data sent by the first ecs, JSON serialized dict containing
          data associated with wait condition signals sent to the handle.
        Value:
          Fn::GetAtt:
          - InstallNginxWaitCondition
          - Data
  • JSON format

    {
      "ROSTemplateFormatVersion": "2015-09-01",
      "Parameters": {
        "InstanceId": {
          "Type": "String",
          "AssociationProperty": "ALIYUN::ECS::Instance::InstanceId"
        }
      },
      "Resources": {
        "InstallNginx": {
          "Type": "ALIYUN::ECS::RunCommand",
          "Properties": {
            "Type": "RunShellScript",
            "CommandContent": {
              "Fn::Sub": "#!/bin/sh\nyum install -y nginx\nsystemctl restart nginx\nif [[ $? -eq 0 ]];\nthen\n${InstallNginxWaitConditionHandle.CurlCli} --data-binary \"{\\\"status\\\": \\\"SUCCESS\\\", \\\"data\\\": \\\"Nginx is installed successfully.\\\"}\"\nelse\n${InstallNginxWaitConditionHandle.CurlCli} --data-binary \"{\\\"status\\\": \\\"FAILURE\\\", \\\"reason\\\": \\\"Failed to install and start nginx.\\\"}\"\nfi\n"
            },
            "Name": "InstallNginxScript",
            "InstanceIds": [
              {
                "Ref": "InstanceId"
              }
            ],
            "Timeout": 60
          }
        },
        "InstallNginxWaitConditionHandle": {
          "Type": "ALIYUN::ROS::WaitConditionHandle"
        },
        "InstallNginxWaitCondition": {
          "Type": "ALIYUN::ROS::WaitCondition",
          "Properties": {
            "Handle": {
              "Ref": "InstallNginxWaitConditionHandle"
            },
            "Timeout": 60
          }
        }
      },
      "Outputs": {
        "InstallNginxData": {
          "Description": "Received the data sent by the first ecs, JSON serialized dict containing data associated with wait condition signals sent to the handle.",
          "Value": {
            "Fn::GetAtt": [
              "InstallNginxWaitCondition",
              "Data"
            ]
          }
        }
      }
    }