本文为您介绍如何通过阿里云CLI(3.0.25以下版本)调用资源栈相关的API。

CreateStacks

创建资源栈。

调用示例

aliyun ros POST /stacks --body '{
  "Template": [Template],
  "Name": "[StackName]",
  "TimeoutMins": 10
}'

创建成功后,返回资源栈名称和ID,否则返回错误信息。

成功示例

$ aliyun ros POST /stacks --body '{
  "Template": {
    "ROSTemplateFormatVersion": "2015-09-01"
  },
  "Name": "ros_test_cli_stack_name",
  "TimeoutMins": 10
}'

{
    "Id": "***-**-**-**-***",
    "Name": "ros_test_cli_stack_name"
}

失败示例

$ aliyun ros POST /stacks --body '{
  "Template": {
    "ROSTemplateFormatVersion": "2015-09-01"
  },
  "Name": "ros_test_cli_stack_name",
  "TimeoutMins": 10
}'

ERROR: SDK.ServerError
ErrorCode: StackExists
Recommend:
RequestId:
Message: The Stack (ros_test_cli_stack_name) already exists.

DeleteStack

删除资源栈。

命令 功能 备注
--RegionId 指定资源栈所在区域 可选。默认值为配置凭证时的区域。
--StackName 指定资源栈的名称 必选
--StackId 指定资源栈的ID 必选

调用示例

aliyun ros DELETE /stacks/[StackName]/[StackId]

删除成功后,提示成功,无返回值,否则返回错误信息。

成功示例

$ aliyun ros DELETE /stacks/ros_test_cli_stack_name/***-**-**-**-***

失败示例

$ aliyun ros DELETE /stacks/ros_test_cli_stack_name/***-**-**-**-***

ERROR: SDK.ServerError
ErrorCode: StackNotFound
Recommend:
RequestId:
Message: The Stack (ros_test_cli_stack_name) could not be found.

UpdateStack

更新资源栈。

命令 功能 备注
--StackName 指定更新资源栈的名称 必选
--StackId 指定更新资源栈的ID 必选

调用示例

aliyun ros UpdateStack --StackName [StackName] --StackId [StackId] --body '{
  "Template": [Template],
  "TimeoutMins": 10
}'

更新成功后,返回资源栈名称和ID,否则返回错误信息。

成功示例

$ aliyun ros PUT /stacks/ros_test_cli_stack_name/***-**-**-**-*** --body '{
  "Template": {
    "ROSTemplateFormatVersion": "2015-09-01"
  },
  "TimeoutMins": 10
}'

{
    "Id": "***-**-**-**-***",
    "Name": "ros_test_cli_stack_name"
}

失败示例

$ aliyun ros PUT /stacks/ros_test_cli_stack_name/***-**-**-**-*** --body '{
  "Template": {
    "ROSTemplateFormatVersion": "2015-09-01",
    "Resources": {
      "Eip": {
        "Type": "ALIYUN::VPC::EIP",
        "Properties": {
          "InternetChargeType": "PayByTraffic",
          "Bandwidth": 200
        }
      }
    },
    "Outputs": {
      "EipAddress": {
        "Value": {
          "Fn::GetAtt": [
            "Eip",
            "EipAddress"
          ]
        }
      },
      "AllocationId": {
        "Value": {
          "Fn::GetAtt": [
            "Eip",
            "AllocationId"
          ]
        }
      }
    }
  },
  "DisableRollback": false,
  "TimeoutMins": 10
}'

ERROR: SDK.ServerError
ErrorCode: NotSupported
Recommend:
RequestId:
Message: Updating a stack when it is in (UPDATE, IN_PROGRESS) is not supported.

PreviewStack

预览资源栈。

调用示例

aliyun ros POST /stacks/preview --body '{
  "Template": [Template],
  "Name": "[StackName]",
  "TimeoutMins": 10
}'

预览成功后,返回模板资源信息,否则返回错误信息。

成功示例

$ aliyun ros POST /stacks/preview --body '{
  "Template": {
    "ROSTemplateFormatVersion": "2015-09-01"
  },
  "Name": "ros_test_cli_stack_name",
  "TimeoutMins": 10
}'

{
  "Updated": null,
  "Description": "No description",
  "Parameters": {
    "ALIYUN::StackId": "None",
    "ALIYUN::AccountId": "**************",
    "ALIYUN::StackName": "ros_test_cli_stack_name",
    "ALIYUN::Region": "cn-hangzhou",
    "ALIYUN::NoValue": "None"
  },
  "Created": "2019-07-20T08:56:48.221264",
  "Region": "cn-hangzhou",
  "TemplateDescription": "No description",
  "Webhook": null,
  "Id": "None",
  "DisableRollback": true,
  "TimeoutMins": 10,
  "Resources": [],
  "Name": "ros_test_cli_stack_name"
}

失败示例

$ aliyun ros POST /stacks/preview --body '{
  "Template": {
    "ROSTemplateFormatVersion": "2015-09-01",
    "Resources": {
      "Eip": {
        "Type": "ALIYUN::VPC::EIP",
        "Properties": {
          "InternetChargeType": "PayByTraffic",
          "BandWidth": 200
        }
      }
    },
    "Outputs": {
      "EipAddress": {
        "Value": {
          "Fn::GetAtt": [
            "Eip",
            "EipAddress"
          ]
        }
      },
      "AllocationId": {
        "Value": {
          "Fn::GetAtt": [
            "Eip",
            "AllocationId"
          ]
        }
      }
    }
  },
  "Name": "ros_test_cli_stack_name",
  "TimeoutMins": 10
}'

ERROR: SDK.ServerError
ErrorCode: StackValidationFailed
Recommend:
RequestId:
Message: Property error: : Resources.Eip.Properties: : Unknown Property BandWidth

AbandonStack

废弃资源栈。

命令 功能 备注
--StackName 指定资源栈的名称 必选
--StackId 指定资源栈的ID 必选

调用示例

aliyun ros DELETE /stacks/[StackName]/[StackId]/abandon

废弃成功后,提示成功,无返回值,否则返回错误信息。

成功示例

$ aliyun ros DELETE /stacks/ros_test_cli_stack_name/***-**-**-**-***/abandon

{
  "Status": "COMPLETE",
  "Name": "ros_test_cli_stack_name",
  "ProjectId": "***************",
  "Environment": {
    "ResourceRegistry": {
      "Resources": {}
    },
    "ParameterDefaults": {},
    "Parameters": {}
  },
  "Template": {
    "ROSTemplateFormatVersion": "2015-09-01"
  },
  "Action": "CREATE",
  "Id": "***-**-**-**-***",
  "Resources": {},
  "StackUserProjectId": null
}

失败示例

$ aliyun ros DELETE /stacks/ros_test_cli_stack_name/***-**-**-**-***/abandon

ERROR: SDK.ServerError
ErrorCode: StackNotFound
Recommend:
RequestId:
Message: The Stack (ros_test_cli_stack_name) could not be found.

DescribeStacks

查询所有资源栈。

命令 功能 备注
--Name 资源栈名称 可选
--StackId 资源栈的ID 可选
--PageNumber 资源栈列表的页码 可选
--PageSize 分页查询时设置的每页行数 可选
--Status 用于过滤的资源栈状态 可选

调用示例

aliyun ros GET /stacks

查询成功后,返回所有资源栈列表。

成功示例

$ aliyun ros GET /stacks

{
    "TotalCount": 1,
    "PageNumber": 1,
    "Stacks": [
        {
            "Status": "CREATE_COMPLETE",
            "Updated": null,
            "Name": "ros_test_cli_stack_name",
            "Created": "2019-07-19T17:00:36",
            "Region": "cn-hangzhou",
            "StatusReason": "Stack CREATE completed successfully",
            "Id": "***-**-**-**-***",
            "DisableRollback": true,
            "TimeoutMins": 60
        }
    ],
    "PageSize": 1
}

DescribeStackDetail

查询资源栈详细信息。

命令 功能 备注
--StackName 指定资源栈的名称 必选
--StackId 指定资源栈的ID 必选

调用示例

aliyun ros GET /stacks/[StackName]/[StackId]

查询成功后,输出资源栈详细信息,否则输出错误信息。

成功示例

$ aliyun ros GET /stacks/ros_test_cli_stack_name/***-**-**-**-***

{
    "Status": "CREATE_COMPLETE",
    "Updated": null,
    "Description": "No description",
    "Parameters": {
        "ALIYUN::StackId": "***-**-**-**-***",
        "ALIYUN::AccountId": "******************",
        "ALIYUN::StackName": "ros_test_cli_stack_name",
        "ALIYUN::Region": "cn-hangzhou",
        "ALIYUN::NoValue": "None"
    },
    "Created": "2019-07-19T13:43:37",
    "Outputs": [],
    "Region": "cn-hangzhou",
    "TemplateDescription": "No description",
    "Webhook": null,
    "StatusReason": "Stack CREATE completed successfully",
    "Id": "[stack_id]",
    "DisableRollback": true,
    "TimeoutMins": 10,
    "Name": "ros_test_cli_stack_name"
}

失败示例

$ aliyun ros GET /stacks/ros_test_cli_stack_name/***-**-**-**-***

ERROR: SDK.ServerError
ErrorCode: StackNotFound
Recommend:
RequestId:
Message: The Stack (ros_test_cli_stack_name) could not be found.