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

For example, assume that you want to create a stack in a web application, and the stack needs to contains one SLB instance, two ECS instances, and one ApsaraDB for RDS instance. If the web application is under heavy workload, you can select an ECS instance that has high specifications when you create the stack. Otherwise, you can select an ECS instance that has lower 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": "The ECS instance type",
    "Description" : "The type of the ECS instance 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 assign a value to the InstanceType parameter when you create stacks based on the template. If this parameter is not specified, 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"
  }
}

Syntax

Each parameter consists of a name and 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 user-friendly parameter names.

The following table describes the parameters.

Parameter Required Description
Type Yes

The data type of the parameter. Valid values:

  • String: a string value. Example: "ecs.s1.medium".
  • Number: an integer or floating-point number. Example: 3.14.
  • CommaDelimitedList: a set of strings separated with commas (,), which can be indexed by using the Fn::Select function. Example: "80, foo, bar".
  • Json: a JSON-formatted string. Example: { "foo": "bar" }, [1, 2, 3].
  • Boolean: a Boolean value. Example: true or false.
Default No If you do not specify a value 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, it is used. Otherwise, an error is returned.
AllowedValues No The list of valid parameter values.
AllowedPattern No The regular expression that is 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 (\\) 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. For example, [a-z-].
MaxLength No The integer value that determines the longest string allowed for a String-type parameter.
MinLength No The integer value that determines the shortest string allowed for a String-type parameter.
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 this parameter is set 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 web forms are generated by using templates, labels can be mapped to parameter names.
AssociationProperty No Automatically checks the validity of the parameter value and provides a list of valid values.
Valid values:
  • ALIYUN::ECS::Instance::ImageId: the ID of the image.
  • ALIYUN::ECS::Instance::ZoneId: available zones for ECS instances
  • ALIYUN::ECS::VPC::VPCId: the ID of the 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 RAM role.
  • ALIYUN::RAM::User: the RAM user.
  • ALIYUN::ECS::KeyPair::KeyPairName: the key pair.
For example, when AssociationProperty is set to ALIYUN::ECS::Instance::ImageId, the ROS console verifies whether the specified image ID is available and lists other values in a drop-down list. For more information, see Examples.
Confirm No Specifies whether to enter the parameter value for a second time if the NoEcho parameter 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 the NoEcho parameter is set to true.

Examples

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

  • UserName: a String-type parameter that is 6 to 12 characters in length. Default value: anonymous. Valid values:
    • anonymous
    • user-one
    • user-two
    Note The default value must also meet the length and valid value requirements.
  • PassWord: a String-type parameter. It does not have a default value. If you set the NoEcho parameter to true, the GetStack operation will not return any parameter values. This parameter 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 the AssociationProperty parameter.to query the list of all available images and check the validity of the default value.
"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"
  }
}