This topic describes how to use Alibaba Cloud CLI to call API operations related to stacks.

CreateStack

You can call this operation to create a stack.

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.

--StackName String Yes MyStack

The name of the stack. 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.

--TimeoutInMinutes Long Yes 10

The timeout period that is specified for the stack creation request. Unit: minutes.

Default value: 10.

--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.

--DisableRollback Boolean No false

Specifies whether to disable rollback on stack creation failure. Default value: false. Valid values:

  • true: disables rollback on stack creation failure.
  • false: enables rollback on stack creation failure.
--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.

--StackPolicyURL String No oss://ros-stack-policy/demo

The URL for the file that contains the stack policy. The URL must point to a policy located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket. Examples: oss://ros/stack-policy/demo and oss://ros/stack-policy/demo?RegionId=cn-hangzhou. If the region of the OSS bucket is not specified, the RegionId parameter value is used by default.

You can specify either the StackPolicyBody parameter or the StackPolicyURL parameter. But you cannot specify both of them.

The policy can be up to 16,384 bytes in length and the URL can be up to 1,350 bytes in length.

--StackPolicyBody String No {"Statement":[{"Action":"Update:*","Resource":"*","Effect":"Allow","Principal":"*"}]}

The structure that contains the stack policy body. The policy body must be 1 to 16,384 bytes in length.

You can specify either the StackPolicyBody parameter or the StackPolicyURL parameter. But you cannot specify both of them.

--NotificationURLs.N RepeatList No http://my-site.com/ros-event

The callback URL for receiving stack event N. Only HTTP POST is supported.

Maximum value of N: 5. Each URL can be up to 1,024 bytes in length.

--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.

--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 CreateStack --StackName MyStack --TemplateBody "{"ROSTemplateFormatVersion": "2015-09-01"}" --TimeoutInMinutes 10

Sample success responses

{
        "StackId": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
        "RequestId": "53C2DB3A-8374-4464-9466-952614EEC159"
}

ListStacks

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

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.

--StackName.N RepeatList No MyStack

The name of stack N. The name must be unique among different stacks. 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.

--Status.N RepeatList No CREATE_COMPLETE

The status of the stack.

Valid values:

  • CREATE_IN_PROGRESS
  • CREATE_FAILED
  • CREATE_COMPLETE
  • UPDATE_IN_PROGRESS
  • UPDATE_FAILED
  • UPDATE_COMPLETE
  • DELETE_IN_PROGRESS
  • DELETE_FAILED
  • DELETE_COMPLETE
  • ROLLBACK_IN_PROGRESS
  • ROLLBACK_FAILED
  • ROLLBACK_COMPLETE
  • CHECK_IN_PROGRESS
  • CHECK_FAILED
  • CHECK_COMPLETE
  • REVIEW_IN_PROGRESS
--ParentStackId String No fgce558a-bdd6-d52j-555b-63755971****

The ID of the parent stack. The ID is used for displaying nested stacks.

--ShowNestedStack Boolean No true

Specifies whether to display nested stacks. This parameter takes effect only when the ParentStackId parameter is specified.

--PageNumber Long No 1

The number of the page to return. Pages start from page 1.

Default value: 1.

--PageSize Long No 10

The number of entries to return on each page. Maximum value: 100.

Default value: 10.

Sample requests

aliyun ros ListStacks --PageNumber 3 --PageSize 1

Sample success responses

{
        "PageNumber": 3,
        "TotalCount": 4,
        "PageSize": 1,
        "RequestId": "B2B3B873-25AE-4A86-B320-8C7298628393",
        "Stacks": [
                {
                        "StatusReason": "Stack CREATE completed successfully",
                        "Status": "CREATE_COMPLETE",
                        "TimeoutInMinutes": 60,
                        "StackId": "aace595a-a00d-4631-858b-61134991****",
                        "RegionId": "cn-beijing",
                        "CreateTime": "2019-08-26T09:52:06",
                        "DisableRollback": false,
                        "StackName": "Test"
                }
        ]
}

GetStack

You can call this operation to query information about a stack.

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 Yes 4a6c9851-3b0f-4f5f-b4ca-a14bf691****

The ID of the stack.

--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 GetStack --RegionId cn-hangzhou --StackId 628e9ed4-899b-4e64-8a8c-2a2b00e4****

Sample success responses

{        
"Parameters": [
                {
                        "ParameterValue": "22536460730754****",
                        "ParameterKey": "ALIYUN::AccountId"
                },
                {
                        "ParameterValue": "cn-beijing",
                        "ParameterKey": "ALIYUN::Region"
                },
                {
                        "ParameterValue": "628e9ed4-899b-4e64-8a8c-2a2b00e4****",
                        "ParameterKey": "ALIYUN::StackId"
                },
                {
                        "ParameterValue": "MyStack",
                        "ParameterKey": "ALIYUN::StackName"
                }
        ],
        "TimeoutInMinutes": 60,
        "Description": "No description",
        "StackId": "628e9ed4-899b-4e64-8a8c-2a2b00e4****",
        "UpdateTime": "2019-08-26T08:27:23",
        "DisableRollback": false,
        "StackName": "MyStack",
        "StatusReason": "Stack successfully updated",
        "Status": "UPDATE_COMPLETE",
        "TemplateDescription": "No description",
        "CreateTime": "2019-08-26T08:26:05",
        "RegionId": "cn-hangzhou",
        "RequestId": "754AEAE5-C800-41EC-A64D-A08C1A4A718F"
}

UpdateStack

You can call this operation to update a stack.

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.

--StackId String Yes 4a6c9851-3b0f-4f5f-b4ca-a14bf691****

The ID of the stack.

--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.

--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.

--StackPolicyDuringUpdateBody String No {"Statement":[{"Effect": "Allow", "Action": "Update:*", "Principal": "*", "Resource": "*"}]}

The structure that contains the body of the temporary overriding stack policy. The policy body must be 1 to 16,384 bytes in length.

To update protected resources, specify a temporary overriding stack policy during this update. If you do not specify a stack policy, the current policy that is associated with the stack will be used.

This parameter takes effect only when the ChangeSetType parameter is set to UPDATE. You can specify only one of the following parameters:

  • StackPolicyBody
  • StackPolicyURL
  • StackPolicyDuringUpdateBody
  • StackPolicyDuringUpdateURL
--TimeoutInMinutes Long No 10

The timeout period that is specified for the stack update request. Unit: minutes.

Default value: 10.

--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.

--StackPolicyURL String No oss://ros-stack-policy/demo

The URL for the file that contains the stack policy. The URL must point to a policy located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket. Examples: oss://ros/stack-policy/demo and oss://ros/stack-policy/demo?RegionId=cn-hangzhou. If the region of the OSS bucket is not specified, the RegionId parameter value is used by default. The policy can be up to 16,384 bytes in length and the URL can be up to 1,350 bytes in length.

You can specify either the StackPolicyBody parameter or the StackPolicyURL parameter. But you cannot specify both of them.

--StackPolicyDuringUpdateURL String No oss://ros-stack-policy/demo

The URL for the file that contains the temporary overriding stack policy. The URL must point to a policy located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket. Examples: oss://ros/stack-policy/demo and oss://ros/stack-policy/demo?RegionId=cn-hangzhou. If the region of the OSS bucket is not specified, the RegionId parameter value is used by default. The policy can be up to 16,384 bytes in length and the URL can be up to 1,350 bytes in length.

To update protected resources, specify a temporary overriding stack policy during this update. If you do not specify a stack policy, the current policy that is associated with the stack will be used.

This parameter takes effect only when the ChangeSetType parameter is set to UPDATE. You can specify only one of the following parameters:
  • StackPolicyBody
  • StackPolicyURL
  • StackPolicyDuringUpdateBody
  • StackPolicyDuringUpdateURL
--StackPolicyBody String No {"Statement": [{"Action": "Update:*", "Resource": "*", "Effect": "Allow", "Principal": "*"}]}

The structure that contains the stack policy body. The policy body must be 1 to 16,384 bytes in length.

You can specify either the StackPolicyBody parameter or the StackPolicyURL parameter. But you cannot specify both of them.

--UsePreviousParameters Boolean No true

Specifies whether to use the values that were passed last time for the parameters that you do not specify in the current request.

--DisableRollback Boolean No false

Specifies whether to disable rollback on stack update failure. Default value: false. Valid values:

  • true: disables rollback on stack update failure.
  • false: enables rollback on stack update failure.
--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 UpdateStack --TemplateBody '{"ROSTemplateFormatVersion": "2015-09-01", "Parameters": {"username": {"Type": "String", "Label": "cli"}}, "Resources": {"TestVPC": {"Type": "ALIYUN::ECS::VPC", "Properties": {"CidrBlock": "172. *. *. */*", "VpcName": "vpc-test"}}}}' --Parameters.1.ParameterKey 'username' --Parameters.1.ParameterValue 'test_parameter' --StackId c18d62d8-51ce-4e8e-b8f6-e00be431****

Sample success responses

{
        "StackId": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
        "RequestId": "53C2DB3A-8374-4464-9466-952614EEC467"
}

PreviewStack

You can call this operation to preview the information of the stack to be created using a specified 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.

--StackName String Yes MyStack

The name of the stack. 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.

--TimeoutInMinutes Long Yes 10

The timeout period that is specified for the stack preview request. Unit: minutes.

Default value: 10.

--Parameters.N.ParameterValue String No ecs.cm4.6xlarge

The value of parameter N.

Maximum value of N: 200.

--Parameters.N.ParameterKey String No InstanceType

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.

--DisableRollback Boolean No false

Specifies whether to disable rollback on stack creation failure. Default value: false. Valid values:

  • true: disables rollback on stack creation failure.
  • false: enables rollback on stack creation failure.
--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.

--StackPolicyURL String No oss://ros-stack-policy/demo

The URL for the file that contains the stack policy. The URL must point to a policy located in an HTTP or HTTPS web server or an Alibaba Cloud OSS bucket. Examples: oss://ros/stack-policy/demo and oss://ros/stack-policy/demo?RegionId=cn-hangzhou. If the region of the OSS bucket is not specified, the RegionId parameter value is used by default. The policy can be up to 16,384 bytes in length and the URL can be up to 1,350 bytes in length.

You can specify either the StackPolicyBody parameter or the StackPolicyURL parameter. But you cannot specify both of them.

--StackPolicyBody String No {"Statement": [{"Action": "Update:*", "Resource": "*", "Effect": "Allow", "Principal": "*"}]}

The structure that contains the stack policy body. The policy body must be 1 to 16,384 bytes in length.

You can specify either the StackPolicyBody parameter or the StackPolicyURL 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.

--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 PreviewStack --StackName PreStack --TimeoutInMinutes 10 --TemplateBody "{"ROSTemplateFormatVersion": "2015-09-01"}"

Sample success responses

{
        "Stack": {
                "Parameters": [
                        {
                                "ParameterValue": "26492326756309****",
                                "ParameterKey": "ALIYUN::AccountId"
                        },
                        {
                                "ParameterValue": "None",
                                "ParameterKey": "ALIYUN::NoValue"
                        },
                        {
                                "ParameterValue": "cn-hangzou",
                                "ParameterKey": "ALIYUN::Region"
                        },
                        {
                                "ParameterValue": "None",
                                "ParameterKey": "ALIYUN::StackId"
                        },
                        {
                                "ParameterValue": "PreStack",
                                "ParameterKey": "ALIYUN::StackName"
                        }
                ],
                "TemplateDescription": "No description",
                "Description": "No description",
                "TimeoutInMinutes": 10,
                "RegionId": "cn-hangzou",
                "DisableRollback": false,
                "Resources": [],
                "StackName": "PreStack"
        },
        "RequestId": "0400B1C6-0CD5-4E6B-A674-9A2507ED07B5"
}

DeleteStack

You can call this operation to delete a stack and all of its resources.

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 Yes 4a6c9851-3b0f-4f5f-b4ca-a14bf691f2ff

The ID of the stack.

--RetainAllResources Boolean No false

Specifies whether to retain the resources in the stack.

Sample requests

aliyun ros DeleteStack --RegionId cn-hangzhou --StackId 3763bb21-5aa2-4a46-86ec-4b149b2f****

Sample success responses

{
        "RequestId": "DC2C269B-C29C-4F07-9A6F-6CE47A267A2F"
}

CancelUpdateStack

You can call this operation to cancel the update of a stack.

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 Yes 4a6c9851-3b0f-4f5f-b4ca-a14bf691****

The ID of the stack.

--CancelType String No Safe

The method to cancel the update operation. We recommend that you set the DisableRollback parameter to true. Valid values:

  • Quick: cancels the update of a stack as soon as possible.
  • Safe: cancels the update of a stack as safely as possible.

Sample requests

aliyun ros CancelUpdateStack --StackId c18d62d8-51ce-4e8e-b8f6-e00be431****

Sample success responses

{
        "RequestId":"F5DFBC9B-1604-4281-B52C-BB35B96018C5"
}

ContinueCreateStack

You can call this operation to create a new stack based on the template of the previous stack that fails to be created. The following table describes parameters of this operation.

Parameters
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 Yes 4a6c9851-3b0f-4f5f-b4ca-a14bf691****

The ID of the stack.

--RecreatingResources.N RepeatList No WebServer

The resource N to be recreated upon creation failure.

You can also list extra resources that resource N is dependent on to recreate them.

Sample requests

aliyun ros ContinueCreateStack --StackId c18d62d8-51ce-4e8e-b8f6-e00be43****

Sample success responses

{
        "StackId":"c18d62d8-51ce-4e8e-b8f6-e00be431****",
        "RequestId":"E7C8199F-2DC4-4D1B-BA5E-7860BF3A530C"
}

ListStackEvents

You can call this operation to query stacks and their resource events.

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 Yes 4a6c9851-3b0f-4f5f-b4ca-a14bf691****

The ID of the stack.

--Status.N RepeatList No CREATE_IN_PROGRESS

The status of resource N. Valid values:

  • CREATE_COMPLETE
  • CREATE_FAILED
  • CREATE_IN_PROGRESS
  • DELETE_FAILED
  • DELETE_IN_PROGRESS
  • ROLLBACK_COMPLETE
  • ROLLBACK_FAILED
  • ROLLBACK_IN_PROGRESS
--ResourceType.N RepeatList No ALIYUN::ECS::Instance

The type of resource N.

Maximum value of N: 200.

--LogicalResourceId.N RepeatList No WebServer

The logical ID of resource N as defined in the template.

--PageNumber Long No 1

The number of the page to return. Pages start from page 1. Default value: 1.

--PageSize Long No 10

The number of entries to return on each page. Maximum value: 100. Default value: 10.

Sample requests

aliyun ros ListStackEvents --StackId c18d62d8-51ce-4e8e-b8f6-e00be431****

Sample success responses

{
        "PageNumber": 1,
        "TotalCount": 2,
        "PageSize": 10,
        "RequestId": "2AE74AAF-F467-4476-AC0E-208C5AE66666",
        "Events": [
                {
                        "StatusReason": "Stack CREATE completed successfully",
                        "Status": "CREATE_COMPLETE",
                        "PhysicalResourceId": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
                        "LogicalResourceId": "test_stack",
                        "ResourceType": "ALIYUN::ROS::Stack",
                        "StackId": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
                        "CreateTime": "2019-09-05T01:27:58",
                        "EventId": "51cc568c-4112-4507-aa8b-d432af5b****",
                        "StackName": "MyStack"
                },
                {
                        "StatusReason": "Stack CREATE started",
                        "Status": "CREATE_IN_PROGRESS",
                        "PhysicalResourceId": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
                        "LogicalResourceId": "test_stack",
                        "ResourceType": "ALIYUN::ROS::Stack",
                        "StackId": "c18d62d8-51ce-4e8e-b8f6-e00be431****",
                        "CreateTime": "2019-09-05T01:27:58",
                        "EventId": "5b9161fc-d4a1-46ef-bbde-a06cceeb****",
                        "StackName": "MyStack"
                }
        ]
}