This topic describes how to use Alibaba Cloud CLI version 3.0.25 or later to call API operations related to templates.

CreateTemplate

You can call this operation to create a template.

Parameter Type Required Example Description
--TemplateName String Yes MyTemplate The name of the template. The name can be up to 255 characters in length and can contain digits, letters, hyphens (-), and underscores (_). It must start with a digit or letter.
--Description String No It is a demo. The description of the template. The description can be up to 256 characters in length.
--TemplateBody String No {"ROSTemplateFormatVersion": "2015-09-01"} The structure that contains the template body. The template body must be 1 to 51,200 bytes in length. You must specify either the TemplateBody parameter or the TemplateURL parameter. But you cannot specify both of them.
--TemplateURL String No oss://ros/template/demo The URL for the file that contains the template body. The URL must point to a template located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket that is in the same region as the stack. Example: oss://ros/template/demo. The template can be up to 524,288 bytes in length. You must specify either the TemplateBody parameter or the TemplateURL parameter. But you cannot specify both of them.

Sample requests

aliyun ros CreateTemplate --TemplateName MyTemplate --TemplateBody "{"ROSTemplateFormatVersion": "2015-09-01"}"

Sample success responses

{
        "RequestId": "24C1BF0F-F65A-45CA-9612-53D0C11BC539",
        "TemplateId": "4237d4b9-31cc-45aa-9c11-6836b2fd****"
}

GetTemplate

You can call this operation to query detailed information about a template, including stacks and change sets associated with the template.

Parameter Type Required Example Description
--RegionId String Yes cn-hangzhou The region ID of the stack. You can call the DescribeRegions operation to query the most recent region list.
--StackId String No 4a6c9851-3b0f-4f5f-b4ca-a14bf691**** The ID of the stack.
--ChangeSetId String No 1f6521a4-05af-4975-afe9-bc4b45ad**** The ID of the change set.

Sample requests

aliyun ros GetTemplate --RegionId cn-beijing  --StackId bd98e636-68e9-4632-82df-ce2aba56****

Sample success responses

{
        "TemplateBody": "{\"ROSTemplateFormatVersion\": \"2015-09-01\", \"Resources\": {\"MyVPC\": {\"Type\": \"ALIYUN::ECS::VPC\", \"Properties\": {\"VpcName\": \"vpc-test\", \"CidrBlock\": \"172.16.0.0/12\"}}}}",
        "RequestId": "3F5F5059-C8C3-473F-ABD3-9647D5384A18"
}

UpdateTemplate

You can call this operation to update a template.

Parameter Type Required Example Description
--TemplateId String Yes 4237d4b9-31cc-45aa-9c11-6836b2fd**** The ID of the template.
--Description String No It is a demo. The description of the template. The description can be up to 256 characters in length.
--TemplateName String No MyTemplate The name of the template. The name can be up to 255 characters in length and can contain digits, letters, hyphens (-), and underscores (_). It must start with a digit or letter.
--TemplateBody String No {"ROSTemplateFormatVersion": "2015-09-01"} The structure that contains the template body. The template body must be 1 to 51,200 bytes in length. You must specify either the TemplateBody parameter or the TemplateURL parameter. But you cannot specify both of them.
--TemplateURL String No oss://ros/template/demo The URL for the file that contains the template body. The URL must point to a template located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket that is in the same region as the stack. Example: oss://ros/template/demo. The template can be up to 524,288 bytes in length. You must specify either the TemplateBody parameter or the TemplateURL parameter. But you cannot specify both of them.

Sample requests

aliyun ros UpdateTemplate --TemplateId 4237d4b9-31cc-45aa-9c11-6836b2fd**** --Description "Add Description"

Sample success responses

{
        "RequestId": "72FA566A-CFCB-49C8-B409-9B2A0C6A2FF4",
        "TemplateId": "4237d4b9-31cc-45aa-9c11-6836b2fd****"
}

ListTemplates

You can call this operation to query the list of templates.

Parameter Type Required Example Description
--PageNumber Long No 10 The number of the page to return. Pages start from page 1. Default value: 1.
--PageSize Long No 1 The number of entries to return on each page. Valid values: 1 to 50. Default value: 10.
--TemplateName String No MyTemplate The name of the template. The name can be up to 255 characters in length and can contain digits, letters, hyphens (-), and underscores (_). It must start with a digit or letter.

Sample requests

aliyun ros ListTemplates --TemplateName "MyTemplate"

Sample success responses

{
        "PageNumber": 1,
        "HttpStatusCode": 200,
        "TotalCount": 1,
        "PageSize": 10,
        "RequestId": "C8A71A8C-5E15-4B94-8BCC-8023C9B8C236",
        "Templates": [
                {
                        "TemplateName": "MyTemplate",
                        "Description": "Add Description",
                        "CreateTime": "2019-10-24T02:29:09.000000",
                        "UpdateTime": "2019-10-24T02:43:35.000000",
                        "TemplateId": "4237d4b9-31cc-45aa-9c11-6836b2fd****"
                }
        ],
        "Success": true
}

DeleteTemplate

You can call this operation to delete a template.

Parameter Type Required Example Description
--TemplateId String Yes 4237d4b9-31cc-45aa-9c11-6836b2fd**** The ID of the template.

Sample requests

aliyun ros DeleteTemplate --TemplateId "4237d4b9-31cc-45aa-9c11-6836b2fd****"

Sample success responses

{
        "RequestId": "56F950C5-966B-4CFB-B350-1E08D770B5CE"
}

GetTemplateEstimateCost

You can call this operation to query estimated prices of resources to be created based on a template.

Parameter Type Required Example Description
--RegionId String Yes cn-beijing The region ID of the stack. You can call the DescribeRegions operation to query the most recent region list.
--Parameters.N.ParameterKey String No InstanceId The key of parameter N. If the key and value of the parameter are not specified, the key and value specified in the template are used. Maximum value of N: 200.
--Parameters.N.ParameterValue String No i-xxxxxx The value of parameter N. Maximum value of N: 200.
--TemplateURL String No oss://ros-template/demo The URL for the file that contains the template body. The URL must point to a template located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket. Examples: oss://ros/template/demo and oss://ros/template/demo?RegionId=cn-hangzhou. If the region of the OSS bucket is not specified, the RegionId parameter value is used by default. The template can be up to 524,288 bytes in length. You must specify either the TemplateBody parameter or the TemplateURL parameter. But you cannot specify both of them.
--TemplateBody String No { "ROSTemplateFormatVersion": "2015-09-01" } The structure that contains the template body. The template body must be 1 to 51,200 bytes in length. You must specify either the TemplateBody parameter or the TemplateURL parameter. But you cannot specify both of them.
--ClientToken String No 123e4567-e89b-12d3-a456-42665544**** The client token that is used to ensure the idempotence of the request. You can use the client to generate the value, but you must ensure that it is unique among different requests. The token can contain only letters, digits, hyphens (-), and underscores(_) and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

Sample requests

aliyun ros GetTemplateEstimateCost --TemplateBody "{'ROSTemplateFormatVersion': '2015-09-01', 'Resources': {'Database': {'Type': 'ALIYUN::RDS::DBInstance', 'Properties': {'Engine':'MySQL', 'EngineVersion':'5.6', 'DBInstanceClass':'rds.mysql.t1.small', 'DBInstanceStorage':'10', 'DBInstanceNetType':'Intranet', 'SecurityIPList': '10.23.XX.XX/XX', 'MasterUsername': 'hope', 'MasterUserPassword': 'lvpd3****', 'DBMappings':[{'DBName': 'hope', 'CharacterSetName': 'utf8'}]}}}}"

Sample success responses

{
        "RequestId": "FF1AB18B-10A4-4C0E-A377-C049728F215B",
        "Resources": {
                "Database": {
                        "Result": {
                                "RequestId": "47E01009-44A4-402D-AA6C-100CED430429",
                                "Order": {
                                        "OriginalAmount": 0.307,
                                        "RuleIds": {
                                                "RuleId": []
                                        },
                                        "TradeAmount": 0.307,
                                        "Coupons": {
                                                "Coupon": []
                                        },
                                        "DiscountAmount": 0.0,
                                        "Currency": "CNY"
                                },
                                "Rules": {
                                        "Rule": []
                                }
                        },
                        "Type": "ALIYUN::RDS::DBInstance",
                        "Success": true
                }
        }
}

ValidateTemplate

You can call this operation to validate the template that is used to create stacks.

Parameter Type Required Example Description
--RegionId String No cn-hangzhou The region ID of the stack template. You can call the DescribeRegions operation to query the most recent region list.
--TemplateBody String No {"ROSTemplateFormatVersion":"2015-09-01"} The structure that contains the template body. The template body must be 1 to 51,200 bytes in length. You must specify either the TemplateBody parameter or the TemplateURL parameter. But you cannot specify both of them.
--TemplateURL String No oss://ros/template/demo The URL for the file that contains the template body. The URL must point to a template located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket. Examples: oss://ros/template/demo and oss://ros/template/demo?RegionId=cn-hangzhou. If the region of the OSS bucket is not specified, the RegionId parameter value is used by default. The template can be up to 524,288 bytes in length. You must specify either the TemplateBody parameter or the TemplateURL parameter. But you cannot specify both of them.

Sample requests

aliyun ros ValidateTemplate --TemplateBody "{"ROSTemplateFormatVersion": "2015-09-01", "Parameters": {"username": {"Type": "String", "Label": "CLI", "Default": "CLITest"}}}"

Sample success responses

{
        "Parameters": [
                {
                        "Default": "CLITest",
                        "NoEcho": "false",
                        "Description": "",
                        "Type": "String",
                        "Label": "CLI",
                        "ParameterKey": "username"
                }
        ],
        "Description": "No description",
        "RequestId": "30FA40B9-82DE-4849-A95C-7D19F308FD20"
}