资源编排服务ROS(Resource Orchestration Service)支持通过模板创建一组阿里云资源。ROS把每组资源定义为一个资源栈(Stack)。ROS通过资源栈管理,分组维护阿里云资源。
前提条件
进行操作前,请确保您已经注册了阿里云账号。如还未注册,请先完成账号注册。
背景信息
本文以simple_ecs_instance模板为例,为您介绍如何在ROS控制台上通过模板创建、管理和维护阿里云资源。ROS模板是JSON格式的文本文件。您可以在这个文本中定义自己的阿里云资源,例如:安全组、ECS实例、VPC、RDS实例等。
操作步骤
- 登录ROS控制台。
- 在左侧导航栏选择模板 > 模板示例。
- 查找模板simple_ecs_instance。
- 单击查看详情,模板会显示为JSON格式。
simple_ecs_instance模板的详细信息如下。
{ "Description": "One simple ECS instance with a security group and a vSwitch in a VPC. The user only needs to specify the image ID.", "Parameters": { "ImageId": { "Type": "String", "Description": { "en": "Image ID, represents the image resource to startup one ECS instance, <a href='https://www.alibabacloud.com/help/doc-detail/112977.htm?userCode=wrvvs1rm&zuntopl' target='_blank'>View image resources</a>", "zh-cn": "镜像ID,详情请参见:<a href='https://help.aliyun.com/document_detail/112977.htm?userCode=wrvvs1rm&zuntopl' target='_blank'>查找镜像</a>。" }, "Label": "ECS Image ID", "Default": "centos_7" }, "InstanceType": { "Type": "String", "Description": { "en": "The ECS instance type, <a href='https://www.alibabacloud.com/help/doc-detail/25378.htm?userCode=wrvvs1rm&zuntopl' target='_blank'>View instance types</a>, please confirm the instance type if in the specific zone in ECS console. ", "zh-cn": "ECS实例规格,详情请参见:<a href='https://help.aliyun.com/document_detail/25378.htm?userCode=wrvvs1rm&zuntopl' target='_blank'>实例规格族</a>ROS" }, "Label": "ECS Instance Type", "Default": "ecs.c5.large" }, "Password": { "NoEcho": true, "Type": "String", "Description": { "en": "[8, 30] characters, consists of uppercase letter, lowercase letter, number or special characters such as ( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ‘ < > , . ? / ", "zh-cn": "长度为8~30个字符。必须同时包含三项(大、小写字母,数字和特殊符号)。<br>支持以下特殊字符:( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ‘ < > , . ? /。" }, "AllowedPattern": "[a-zA-Z0-9-\\(\\)\\`\\~\\!@\\#\\$%\\^&\\*-+=\\|\\{\\}\\[\\]\\:\\;\\‘\\,\\.\\?\\/]*", "Label": "Login Password", "ConstraintDescription": "[8, 30] characters, consists of uppercase letter, lowercase letter, number or special characters.", "MinLength": 8, "MaxLength": 30 } }, "ROSTemplateFormatVersion": "2015-09-01", "Outputs": { "InstanceId": { "Description": "The instance id of created ecs instance", "Value": { "Fn::GetAtt": [ "WebServer", "InstanceId" ] } }, "PublicIp": { "Description": "Public IP address of created ecs instance.", "Value": { "Fn::GetAtt": [ "WebServer", "PublicIp" ] } }, "SecurityGroupId": { "Description": "Generated security group id for security group.", "Value": { "Fn::GetAtt": [ "SecurityGroup", "SecurityGroupId" ] } } }, "Resources": { "VSwitch": { "Type": "ALIYUN::ECS::VSwitch", "Properties": { "VpcId": { "Ref": "VPC" }, "ZoneId": { "Fn::Select": [ "0", { "Fn::GetAZs": { "Ref": "ALIYUN::Region" } } ] }, "CidrBlock": "192.168.XX.XX/16" } }, "WebServer": { "Type": "ALIYUN::ECS::Instance", "Properties": { "VpcId": { "Ref": "VPC" }, "SecurityGroupId": { "Ref": "SecurityGroup" }, "VSwitchId": { "Ref": "VSwitch" }, "ImageId": { "Ref": "ImageId" }, "InstanceType": { "Ref": "InstanceType" }, "Password": { "Ref": "Password" } } }, "VPC": { "Type": "ALIYUN::ECS::VPC", "Properties": { "CidrBlock": "192.168.XX.XX/16", "VpcName": "simple_ecs_vpc" } }, "SecurityGroup": { "Type": "ALIYUN::ECS::SecurityGroup", "Properties": { "VpcId": { "Ref": "VPC" } } } } }
这个JSON文本包含5个一级字段:"ROSTemplateFormatVersion"
定义模板的版本。"Description"
定义模板的解释说明。"Parameters" : { }
定义模板的参数。本例定义了镜像ID和实例规格等参数,并指定了参数的默认值。"Resources" : { }
定义模板可创建的阿里云资源。本例将创建一个ECS实例和一个安全组,资源属性将引用Parameters
中定义的参数。"Outputs": { }
定义资源创建完成后,通过ROS输出栈的资源信息。本实例将输出ECS实例的ID、公网IP和安全组ID。
- 单击右上角的创建资源栈。
- 在配置模板参数页面,输入密码信息,单击创建。