Creates a stack.

A stack is a collection of Resource Orchestration Service (ROS) resources that you can manage as a single unit. To create a collection of resources, you can create a stack. For more information about stacks, see Overview.

When you call this operation, you must take note of the following limits:

  • You can create up to 200 stacks within an Alibaba Cloud account.
  • You can create up to 200 resources in a stack.

This topic provides an example on how to create a stack named MyStack in the China (Hangzhou) region. The template body of the stack is {"ROSTemplateFormatVersion":"2015-09-01"}.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

ParameterTypeRequiredExampleDescription
ActionStringYesCreateStack

The operation that you want to perform. Set the value to CreateStack.

DisableRollbackBooleanNofalse

Specifies whether to disable rollback for the resources when the stack fails to be created.

Default value: false. Valid values:

  • true
  • false
TemplateBodyStringNo{"ROSTemplateFormatVersion":"2015-09-01"}

The structure that contains the template body. The template body must be 1 to 524,288 bytes in length. If the length of the template body exceeds the upper limit, we recommend that you add parameters to the HTTP POST request body to prevent request failures caused by excessively long URLs.

Note You must specify only one of the following parameters: TemplateBody, TemplateURL, TemplateId, and TemplateScratchId.
StackPolicyURLStringNooss://ros-stack-policy/demo

The URL of the file that contains the stack policy. The URL must point to a policy that is located on an HTTP or HTTPS web server or in an Object Storage Service (OSS) bucket, such as oss://ros/stack-policy/demo or oss://ros/stack-policy/demo?RegionId=cn-hangzhou. The policy file can be up to 16,384 bytes in length. If you do not specify the region ID of the OSS bucket, the value of the RegionId parameter is used.

Note You can specify only one of the StackPolicyBody and StackPolicyURL parameters.

The URL can be up to 1,350 bytes in length.

TimeoutInMinutesLongNo10

The timeout period that is allowed to create the stack.

  • Default value: 60.
  • Unit: minutes.
  • Valid values: 10 to 1440.
StackPolicyBodyStringNo{"Statement": [{"Action": "Update:*", "Resource": "*", "Effect": "Allow", "Principal": "*"}]}

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

Note You can specify only one of the StackPolicyBody and StackPolicyURL parameters.
StackNameStringYesMyStack

The name of the stack.

The name can be up to 255 characters in length, and can contain digits, letters, hyphens (-), and underscores (_). The name must start with a letter.

RegionIdStringYescn-hangzhou

The region ID of the stack. You can call the DescribeRegions operation to query the most recent region list.

ClientTokenStringNo123e4567-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 make sure that the value is unique among different requests. The token can be up to 64 characters in length, and can contain letters, digits, hyphens (-), and underscores (_).

For more information, see Ensure idempotence.

TemplateURLStringNooss://ros-template/demo

The URL of the file that contains the template body. The URL must point to a template that is located on an HTTP or HTTPS web server or in an OSS bucket, such as oss://ros/stack-policy/demo or oss://ros/stack-policy/demo?RegionId=cn-hangzhou. The template body can be up to 524,288 bytes in length. If you do not specify the region ID of the OSS bucket, the value of the RegionId parameter is used.

Note You must specify only one of the following parameters: TemplateBody, TemplateURL, TemplateId, and TemplateScratchId.
RamRoleNameStringNotest-role

The name of the RAM role. ROS assumes the RAM role to create the stack and uses credentials of the role to call the APIs of Alibaba Cloud services.

ROS assumes the RAM role to perform operations on the stack. If you have permissions to perform operations on the stack but do not have permissions to use the RAM role, ROS still assumes the RAM role. You must make sure that the least privileges are granted to the RAM role.

If you do not specify this parameter, ROS assumes the existing role that is associated with the stack. If no roles are available, ROS uses a temporary credential that is generated from the credentials of your account.

The name can be up to 64 characters in length.

DeletionProtectionStringNoEnabled

Specifies whether to enable deletion protection for the stack. Default value: Disabled. Valid values:

  • Enabled: enables deletion protection.
  • Disabled: disables deletion protection. You can delete the stack by using the ROS console or by calling the DeleteStack operation.
Note The DeletionProtection parameter that you specify for the root stack applies to its nested stacks.
CreateOptionStringNoKeepStackOnCreationComplete

The option for the stack after you create the stack. Default value: KeepStackOnCreationComplete. Valid values:

  • KeepStackOnCreationComplete: retains the stack and its resources after the stack is created. In this case, your stack quota in ROS is consumed.
  • AbandonStackOnCreationComplete: deletes the stack, but retains its resources after the stack is created. In this case, your stack quota in ROS is not consumed. If the stack fails to be created, the stack is retained.
  • AbandonStackOnCreationRollbackComplete: deletes the stack when its resources are rolled back after the stack fails to be created. In this case, your stack quota in ROS is not consumed. In other rollback scenarios, the stack is retained.
TemplateIdStringNo5ecd1e10-b0e9-4389-a565-e4c15efc****

The ID of the template. This parameter applies to shared templates and private templates.

Note You must specify only one of the following parameters: TemplateBody, TemplateURL, TemplateId, and TemplateScratchId.
TemplateVersionStringNov1

The version of the template. This parameter takes effect only when the TemplateId parameter is specified.

Parameters.N.ParameterKeyStringYesInstanceId

The name of parameter N that is defined in the template. If you do not specify the name and value of a parameter, ROS uses the default name and value in the template.

Maximum value of N: 200.

The name must be 1 to 128 characters in length, and cannot contain http:// or https://. The name cannot start with aliyun or acs:.

Note The Parameters parameter is optional. If you specify Parameters, you must specify both Parameters.N.ParameterKey and Parameters.N.ParameterValue.
Parameters.N.ParameterValueStringYesi-xxxxxx

The value of parameter N that is defined in the template.

Maximum value of N: 200.

The value can be up to 128 characters in length, and cannot contain http:// or https://. The value cannot start with aliyun or acs:.

Note The Parameters parameter is optional. If you specify Parameters, you must specify both Parameters.N.ParameterKey and Parameters.N.ParameterValue.
NotificationURLs.NStringNohttp://example.com/ros-event

The callback URL that is used to receive stack event N. Valid values:

  • HTTP POST URL

    Each URL can be up to 1,024 bytes in length.

  • eventbridge

    When the status of a stack changes, ROS sends an event notification to the EventBridge service. You can view the event information in the EventBridge console.
    Note ROS supports the EventBridge service in the following regions: China (Hangzhou), China (Shanghai), China (Beijing), China (Hong Kong), and China (Zhangjiakou).

Maximum value of N: 5. When the status of a stack changes, ROS sends an event notification to the specified URL. When rollback is enabled for the stack, event notifications are sent if the stack is in the CREATE_ROLLBACK or ROLLBACK state, but are not sent if the stack is in the CREATE_FAILED, UPDATE_FAILED, or IN_PROGRESS state.

ROS sends event notifications regardless of whether you configure the Outputs section. The following sample code provides an example on the content of an event notification:


{
    "Outputs": [
        {
            "Description": "No description given",
            "OutputKey": "InstanceId",
            "OutputValue": "i-xxx"
        }
    ],
    "StackId": "80bd6b6c-e888-4573-ae3b-93d29113****",
    "StackName": "test-notification-url",
    "Status": "CREATE_COMPLETE"
}
                                    
Tags.N.KeyStringYesusage

The key of tag N that you want to add to the stack.

Valid values of N: 1 to 20.

Note
  • The Tags parameter is optional. If you specify the Tags parameter, you must specify the Tags.N.Key parameter.
  • The tag of a stack is propagated to each stack resource that supports the tag feature. For more information, see Propagate tags.
Tags.N.ValueStringNotest

The value of tag N that you want to add to the stack.

Valid values of N: 1 to 20.

Note The tag of a stack is propagated to each stack resource that supports the tag feature. For more information, see Propagate tags.
ResourceGroupIdStringNorg-acfmxazb4ph6aiy****

The ID of the resource group. If you do not specify this parameter, the stack is added to the default resource group.

For more information about resource groups, see the "Resource Group" section of the What is Resource Management? topic.

ParallelismLongNo1

The maximum number of concurrent operations that can be performed on resources.

By default, this parameter is empty. You can set this parameter to an integer that is greater than or equal to 0.

Note
  • If you set this parameter to an integer that is greater than 0, the integer is used. If you set this parameter to 0 or leave this parameter empty, no limit is imposed on ROS stacks. However, the default value in Terraform is used for Terraform stacks. In most cases, the default value in Terraform is 10.
  • If you set this parameter to a specific value, ROS associates the value with the stack. The value affects subsequent operations on the stack, such as an update operation.
TemplateScratchIdStringNots-aa9c62feab844a6b****

The ID of the scenario.

For more information about how to query the IDs of scenarios, see ListTemplateScratches.

Note You must specify only one of the following parameters: TemplateBody, TemplateURL, TemplateId, and TemplateScratchId.
TemplateScratchRegionIdStringNocn-hangzhou

The region ID of the scenario. The default value is the same as the value of the RegionId parameter.

You can call the DescribeRegions operation to query the most recent region list.

For more information about common request parameters, see Common parameters.

Response parameters

ParameterTypeExampleDescription
RequestIdStringB288A0BE-D927-4888-B0F7-B35EF84B6E6F

The ID of the request.

StackIdString4a6c9851-3b0f-4f5f-b4ca-a14bf691****

The ID of the stack.

Examples

Sample requests

http(s)://ros.aliyuncs.com/?Action=CreateStack
&StackName=MyStack
&RegionId=cn-hangzhou
&Parameters=[{"ParameterKey":"InstanceId","ParameterValue":"i-xxxxxx"}]
&Tags=[{"Key":"usage"}]
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<CreateStackResponse>
        <StackId>4a6c9851-3b0f-4f5f-b4ca-a14bf691****</StackId>
        <RequestId>B288A0BE-D927-4888-B0F7-B35EF84B6E6F</RequestId>
</CreateStackResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

{
  "StackId" : "4a6c9851-3b0f-4f5f-b4ca-a14bf691****",
  "RequestId" : "B288A0BE-D927-4888-B0F7-B35EF84B6E6F"
}

Error codes

For a list of error codes, see Service error codes.

Error code

Error message

HTTPS status code

Description

CircularDependency

Circular Dependency Found: {reason}.

400

The error message returned because the template contains circular dependencies. reason indicates the cause of the error.

InvalidSchema

{reason}.

400

The error message returned because the format of the template is invalid. reason indicates the cause of the error.

InvalidTemplateAttribute

The Referenced Attribute ({resource} {name}) is incorrect.

400

The error message returned because the resource property that is referenced in the Outputs section of the template is invalid. resource indicates the resource name. name indicates the property name.

InvalidTemplatePropertyType

The specified value type of ({resource} {section}) is incorrect.

400

The error message returned because the type of the resource property that is defined in a section of the template is invalid. resource indicates the resource name. section indicates the section name.

InvalidTemplateReference

The specified reference "{name}" (in {referencer}) is incorrect.

400

The error message returned because the template contains an invalid reference. name indicates the reference name. referencer indicates the referencer name.

InvalidTemplateSection

The template section is invalid: {section}.

400

The error message returned because the template contains an invalid section. section indicates the section name.

InvalidTemplateVersion

The template version is invalid: {reason}.

400

The error message returned because the template version is invalid. reason indicates the cause of the error.

StackValidationFailed

{reason}.

400

The error message returned because the stack failed to be validated. reason indicates the cause of the error.

UnknownUserParameter

The Parameter ({name}) was not defined in template.

400

The error message returned because the specified parameter is not defined in the template. name indicates the parameter name.

UserParameterMissing

The Parameter {name} was not provided.

400

The error message returned because no value is specified for the specified parameter that is defined in the template. name indicates the parameter name.

ActionInProgress

Stack {name} already has an action ({action}) in progress.

409

The error message returned because the stack is being changed. name indicates the name or ID of the stack. action indicates the change operation.

StackExists

The Stack ({name}) already exists.

409

The error message returned because a stack that has the same name already exists. name indicates the stack name.

TemplateNotFound

The Template ({ ID }) could not be found.

404

The error message returned because the specified template does not exist. ID indicates the template ID.

TemplateNotFound

The Template { ID } with version { version } could not be found.

404

The error message returned because the specified template or template version does not exist. ID indicates the template ID. version indicates the template version.