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.

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

Parameter Type Required Example Description
Action String Yes CreateStack

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

DisableRollback Boolean No false

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

Default value: false. Valid values:

  • true: disables rollback of the stack when the stack fails to be created.
  • false: enables rollback of the stack when the stack fails to be created.
TemplateBody String No {"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.
StackPolicyURL String No oss://ros-stack-policy/demo

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

Note You can specify only one of the StackPolicyBody and StackPolicyURL parameters.
TimeoutInMinutes Long No 10

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

  • Default value: 60.
  • Unit: minutes.
StackPolicyBody String No {"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.
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.

RegionId String Yes cn-hangzhou

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

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 make sure that it 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.

TemplateURL String No oss://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 Alibaba Cloud OSS bucket, for examples, oss://ros/stack-policy/demo and oss://ros/stack-policy/demo?RegionId=cn-hangzhou. The template can be up to 524,288 bytes in length. If you do not specify RegionId in the URL, the region ID of the stack group is used.

Note You must specify only one of the following parameters: TemplateBody, TemplateURL, TemplateId, and TemplateScratchId.
RamRoleName String No test-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 you do not have permissions to use the RAM role, ROS still uses the RAM role. You must make sure that the least privileges are granted to the role.

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

The RAM role name can be up to 64 characters in length.

DeletionProtection String No Enabled

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

  • Enabled: enables deletion protection on the stack.
  • Disabled: disables deletion protection on the stack. You can release the stack by using the ROS console or calling the DeleteStack operation.
Note The value of the DeletionProtection parameter of a nested stack must be the same as the value of the DeletionProtection parameter of its root stack.
CreateOption String No KeepStackOnCreationComplete

Specifies whether to delete the stack after the stack is created. Default value: KeepStackOnCreationComplete. Valid values:

  • KeepStackOnCreationComplete: retains the stack and all of its resources after the stack is created.
  • AbandonStackOnCreationComplete: deletes the stack but retains all of its resources after the stack is created. This ensures that the maximum number of stacks allowed to be created is not reached. If the stack fails to be created, the stack is retained.
  • AbandonStackOnCreationRollbackComplete: deletes the stack after rollback on stack creation failure is complete. This ensures that the maximum number of stacks allowed to be created is not reached. If the stack is created or the rollback fails to complete, the stack is retained.
TemplateId String No 5ecd1e10-b0e9-4389-a565-e4c15efc****

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

Note You must specify only one of the following parameters: TemplateBody, TemplateURL, TemplateId, and TemplateScratchId.
TemplateVersion String No v1

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

ResourceGroupId String No rg-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 What is Resource Management?

Parallelism Long No 1

The maximum number of concurrent operations that are performed on resources. This parameter only takes effect for Terraform stacks.

This parameter is empty by default. You can set this parameter to an integer greater than or equal to 0.

Note
  • If you set this parameter to an integer greater than 0, the integer is used. If you do not set this parameter or set it to 0, the default value 10 is used.
  • If you set this parameter, ROS associates the value with the stack and the value can affect subsequent operations on the stack, such as updating a stack.
TemplateScratchId String No ts-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.
TemplateScratchRegionId String No cn-hangzhou

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

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

Parameters.N.ParameterKey String Yes InstanceId

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

Maximum value of N: 200.

Note Parameters in Parameters.N.ParameterKey is optional. If you need to specify Parameters, you must specify both Parameters.N.ParameterKey and Parameters.N.ParameterValue.
Parameters.N.ParameterValue String Yes i-xxxxxx

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

Maximum value of N: 200.

Note Parameters in Parameters.N.ParameterValue is optional. If you need to specify Parameters, you must specify both Parameters.N.ParameterKey and Parameters.N.ParameterValue.
NotificationURLs.N String No http://my-site.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 event notifications 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. ROS sends a notification to the specified URL when the stack status changes. If rollback is enabled on the stack, notifications are sent when the stack is in the CREATE_ROLLBACK or ROLLBACK state, but are not sent when the stack is in the CREATE_FAILED or UPDATE_FAILED state. ROS does not send notifications when the stack is in the IN_PROGRESS state.

Notifications are sent regardless of whether the Outputs parameter is specified. The following sample code shows 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.Key String Yes usage

The key of tag N of the stack.

Valid values of N: 1 to 20.

Note Tags in Tags.N.Key is optional. If you need to specify Tags, you must specify the Tags.N.Key parameter.
Tags.N.Value String No test

The value of tag N of the stack.

Valid values of N: 1 to 20.

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

Response parameters

Parameter Type Example Description
RequestId String B288A0BE-D927-4888-B0F7-B35EF84B6E6F

The ID of the request.

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

The ID of the stack.

Examples

Sample requests

http(s)://ros.aliyuncs.com/?Action=CreateStack
&TemplateBody={"ROSTemplateFormatVersion":"2015-09-01"}
&StackName=MyStack
&RegionId=cn-hangzhou
&<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, visit the API Error Center.

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 template format 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 specified resource property that is defined in 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 fails 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 set 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 specified stack has a change operation in progress. 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 with 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.