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
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 for the resources when the stack fails to be created. Default value: false. Valid values:
|
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 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. |
TimeoutInMinutes | Long | No | 10 | The timeout period that is allowed to create the stack.
|
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 (_). The name must start with a 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 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. |
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 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. |
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 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. |
DeletionProtection | String | No | Enabled | Specifies whether to enable deletion protection for the stack. Default value: Disabled. Valid values:
Note The DeletionProtection parameter that you specify for the root stack applies to its nested stacks. |
CreateOption | String | No | KeepStackOnCreationComplete | The option for the stack after you create the stack. Default value: KeepStackOnCreationComplete. Valid values:
|
TemplateId | String | No | 5ecd1e10-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. |
TemplateVersion | String | No | v1 | The version of the template. This parameter takes effect only when the TemplateId parameter is specified. |
Parameters.N.ParameterKey | String | Yes | InstanceId | 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 Note The Parameters parameter is optional. If you 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. The value can be up to 128 characters in length, and cannot contain Note The Parameters parameter is optional. If you specify Parameters, you must specify both Parameters.N.ParameterKey and Parameters.N.ParameterValue. |
NotificationURLs.N | String | No | http://example.com/ros-event | The callback URL that is used to receive stack event N. Valid values:
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:
|
Tags.N.Key | String | Yes | usage | The key of tag N that you want to add to the stack. Valid values of N: 1 to 20. Note
|
Tags.N.Value | String | No | test | 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. |
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 the "Resource Group" section of the What is Resource Management? topic. |
Parallelism | Long | No | 1 | 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
|
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 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
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
&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. |