The Parameters section improves the flexibility and reusability of a template. When you create a stack, you can replace parameter values in the template.

Syntax

Each parameter consists of a name and several properties. The parameter name can contain only letters and digits and must be unique within the template. You can use the Label field to define the alias of a parameter.

The following table describes the parameter properties.

Parameter property Required Description
Type No

The data type of the parameter. Valid values:

  • String: a string value. Example: "ecs.s1.medium".
  • Number: an integer or a floating-point number. Example: 3.14.
  • CommaDelimitedList: a set of string values separated by commas (,). You can use the Fn::Select function to select an element from the string list. Example: "80, foo, bar".
  • Json: a JSON string. Example: { "foo": "bar" }, [1, 2, 3].
  • Boolean: a Boolean value. Example: true or false.
  • ALIYUN::OOS::Parameter::Value: a common parameter stored in Operation Orchestration Service (OOS) Parameter Store. Example: my_image.
  • ALIYUN::OOS::SecretParameter::Value: an encryption parameter stored in OOS Parameter Store. Example: my_password.
Note The ALIYUN::OOS::Parameter::Value and ALIYUN::OOS::SecretParameter::Value parameter types cannot be verified by the AllowedPattern property.
Default No The default value of the parameter. If you do not specify a value for the parameter when you create a stack, Resource Orchestration Service (ROS) checks whether a default value is defined in the template. If a default value is found, ROS uses the default value. Otherwise, an error is returned.
Note The default value can be set to null, which indicates that this parameter is left empty and the parameter verification is skipped.
AllowedValues No The list of one or more valid parameter values.
AllowedPattern No The regular expression used to check whether the specified parameter value is a string. If the input is not a string, an error is returned.

If you use the following special characters, add two backslashes (\\) immediately before the characters to escape:

*.?+-$^[ ]( ){ }|\/
Note A hyphen (-) does not need to be escaped if it is the first or last character in the range. Example: [a-z-].
MaxLength No The integer value that determines the maximum length of String-type parameters.
MinLength No The integer value that determines the minimum length of String-type parameters.
MaxValue No The numeric value that determines the maximum value allowed for a Number-type parameter.
MinValue No The numeric value that determines the minimum value allowed for a Number-type parameter.
NoEcho No Specifies whether to mask the parameter value when the GetStack operation is called. If you set this parameter property to true, only asterisks (*) are returned.
Description No The string that describes the parameter.
ConstraintDescription No The string that explains the parameter constraint.
Label No The alias of the parameter, encoded in UTF-8. When you create a web form based on a template, the value of the label field can be mapped to the parameter name.
AssociationProperty No The associated resource property. If you specify this parameter property, ROS verifies whether the specified parameter value is valid and provides a list of valid values based on the associated resource property.
Valid values:
  • ALIYUN::ECS::Instance::ImageId: the ID of the image.
  • ALIYUN::ECS::Instance::ZoneId: the zone ID of the Elastic Compute Service (ECS) instance.
  • ALIYUN::ECS::VPC::VPCId: the ID of the virtual private cloud (VPC).
  • ALIYUN::ECS::VSwitch::VSwitchId: the ID of the vSwitch.
  • ALIYUN::ECS::Instance::InstanceType: the instance type of the ECS instance.
  • ALIYUN::ECS::SecurityGroup::SecurityGroupId: the ID of the security group.
  • ALIYUN::RAM::Role: the Resource Access Management (RAM) role.
  • ALIYUN::RAM::User: the RAM user.
  • ALIYUN::ECS::KeyPair::KeyPairName: the name of the key pair.
For example, if you set AssociationProperty to ALIYUN::ECS::Instance::ImageId, the ROS console verifies whether the specified image ID is valid and lists other valid values in a drop-down list. For more information, see Example 2: Use the UserName, PassWord, and ImageId parameters.
AssociationPropertyMetadata No The metadata map that explains the constraint of AssociationProperty.

Valid values:

  • ZoneId: the ID of the zone. If you set the parameter property to ZoneId, ROS queries the resources in the specified zone.

    Applicable AssociationProperty value: ALIYUN::ECS::VSwitch::VSwitchId.

  • VpcId: the ID of the VPC. If you set the parameter property to VpcId, ROS queries the resources in the specified VPC.
    Applicable AssociationProperty values:
    • ALIYUN::ECS::VSwitch::VSwitchId
    • ALIYUN::ECS::SecurityGroup::SecurityGroupId
For more information, see Example 3: Use the AssociationPropertyMetadata parameter property.
Confirm No Specifies whether to enter the parameter value a second time if NoEcho is set to true. Default value: false.
Note Confirm can be set to true only when it is used with a String-type parameter and when NoEcho is set to true.
TextArea No Specifies whether the parameter supports line breaks. Default value: false. Valid values:
  • true: Line breaks are supported.
  • false: Line breaks are not supported.

For example, the following code indicates that the Content parameter supports line breaks.

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "Content": {
      "Type": "String",
      "TextArea": true
    }
  },
  "Outputs": {
    "TestContent": {
      "Value": {
        "Ref": "Content"
      }
    }
  }
}

Example 1: Use the InstanceType parameter to create a stack in a web application

For example, you want to create a stack in a web application, and the stack needs to contain one Server Load Balancer (SLB) instance, two ECS instances, and one ApsaraDB RDS instance. If the web application is under heavy workload, you can select an ECS instance that has advanced specifications when you create the stack. If the web application is not under heavy workload, you can select an ECS instance that has basic specifications. The following example shows how to define the InstanceType parameter for an ECS instance:

"Parameters" : {
  "InstanceType" : {
    "Type" : "String",
    "AllowedValues":["ecs.t1.small","ecs.s1.medium", "ecs.m1.medium", "ecs.c1.large"],
    "Default": "ecs.t1.small",
    "Label": "ECS instance type",
    "Description" : "The type of the ECS instance that you want to create. Default value: ecs.t1.small. Valid values: ecs.t1.small, ecs.s1.medium, ecs.m1.medium, and ecs.c1.large."
  }
}

You can specify the InstanceType parameter each time when you create a stack based on the template. If you do not specify the parameter, the default value ecs.t1.small is used.

The following example shows how to reference the InstanceType parameter when you define a resource:

"Webserver" : {
  "Type" : "ALIYUN::ECS::Instance",
  "InstanceType": {
    "Ref": "InstanceType"
  }
}

Example 2: Use the UserName, PassWord, and ImageId parameters

In the following example, three parameters are defined in the Parameters section.

  • UserName: a String-type parameter whose value must be 6 to 12 characters in length. Default value: anonymous. Valid values:
    • anonymous
    • user-one
    • user-two
    Note The default value anonymous must also meet the length and valid value requirements.
  • PassWord: a String-type parameter that does not have a default value. If you set the NoEcho parameter property to true, the GetStack operation does not return parameter values. The PassWord value must be 1 to 41 characters in length and can contain uppercase letters, lowercase letters, and digits.
  • ImageId: a String-type parameter. You can use AssociationProperty to query the list of all available images and check whether the default value is valid.
"Parameters": {
  "UserName": {
    "Label": "Username"
    "Description": "Enter the username"
    "Default": "anonymous",
    "Type": "String",
    "MinLength": "6",
    "MaxLength": "12",
    "AllowedValues": [
      "anonymous",
      "user-one",
      "user-two"
    ]
  },
  "PassWord": {
    "Label": "Password"
    "NoEcho": "True",
    "Description": "Enter the password"
    "Type": "String",
    "MinLength": "1",
    "MaxLength": "41",
    "AllowedPattern": "[a-zA-Z0-9]*"
  },
  "ImageId": {
    "Label": "Image",
    "Type": "String",
    "Description": "Select an image",
    "AssociationProperty": "ALIYUN::ECS::Instance::ImageId",
    "Default": "centos_7_7_x64_20G_alibase_2020****.vhd"
  }
}

Example 3: Use the AssociationPropertyMetadata parameter property

If you specify the AssociationPropertyMetadata parameter property, the ROS console lists available vSwitches in a drop-down list that are located in the specified zone and VPC. If you do not specify the AssociationPropertyMetadata parameter property, the ROS console lists all vSwitches in the current region.

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "VpcId": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VPC::VPCId"
    },
    "EcsZone": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId"
    },
    "VSwitchId": {
      "Type": "String",
      "AssociationProperty": "ALIYUN::ECS::VSwitch::VSwitchId",
      "AssociationPropertyMetadata": {
        "VpcId": "VpcId",
        "ZoneId": "EcsZone"
      }
    }
  }
}