閱讀104 返回首頁    go 阿裏雲 go 技術社區[雲棲]


通過資源編排創建一個ECS實例

快速創建ECS實例

創建了安全組之後,就可以來創建ECS的實例了。

ROS提供了兩種資源可以生成ECS的實例,一種資源是ALIYUN::ECS::InstanceClone, 它支持快速的從已有的ECS實例克隆一個資源,另外一種是ALIYUN::ECS::Instance支持按照配置生成一個ECS資源。

下麵通過簡單的介紹如何創建一個ECS實例。

通過已有的ECS實例進行克隆

通過ALIYUN::ECS::InstanceClone的屬性定義。隻有一個必選參數就是SourceInstanceId,這個資源將會拷貝源實例:

  • 實例規格
  • 鏡像ID
  • 安全組ID
  • 係統盤類型,名稱,描述
  • 數據盤類型,名稱,描述,如果從快照創建,則從快照拷貝
  • 網絡配置,網絡付費類型,網絡帶寬
  • VPC類型的拷貝VSwitch

除了上麵的屬性,依然支持指定下麵的屬性,如果指定下麵的屬性就會覆蓋默認屬性的配置:

  • 實例名稱
  • 實例描述
  • 安全組ID
  • 實例密碼
  • Tags配置

對於密碼屬性,設置NoEcho為True,則顯示為密碼。

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "Password": {
      "Description": "實例的密碼。8-30個字符,必須同時包含三項(大、小寫字母,數字和特殊符號)。支持以下特殊字符:( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ' < > , . ? /",
      "NoEcho": true,
      "Type": "String"
    },
    "SourceInstanceId": {
      "Description": "源ECS InstanceId拷貝",
      "Type": "String"
    }
  },
  "Resources": {
    "InstanceClone": {
      "Properties": {
        "Password": {
          "Ref": "Password"
        },
        "SourceInstanceId": {
          "Ref": "SourceInstanceId"
        }
      },
      "Type": "ALIYUN::ECS::InstanceClone"
    }
  },
  "Outputs": {
    "InnerIp": {
      "Description": "Inner IP address of the specified instance. Only for classical instance.",
      "Value": {
        "Fn::GetAtt": [
          "InstanceClone",
          "InnerIp"
        ]
      }
    },
    "InstanceId": {
      "Description": "The instance id of created ecs instance",
      "Value": {
        "Fn::GetAtt": [
          "InstanceClone",
          "InstanceId"
        ]
      }
    },
    "PrivateIp": {
      "Description": "Private IP address of created ecs instance. Only for VPC instance.",
      "Value": {
        "Fn::GetAtt": [
          "InstanceClone",
          "PrivateIp"
        ]
      }
    },
    "PublicIp": {
      "Description": "Public IP address of created ecs instance.",
      "Value": {
        "Fn::GetAtt": [
          "InstanceClone",
          "PublicIp"
        ]
      }
    },
    "ZoneId": {
      "Description": "Zone id of created instance.",
      "Value": {
        "Fn::GetAtt": [
          "InstanceClone",
          "ZoneId"
        ]
      }
    }
  }
}

使用模板創建一個ECS實例

創建一個ECS實例,有幾個必選屬性:

  • SecurityGroupId: 安全組Id
  • InstanceType: 實例規格, 參考ROS控製台的 關鍵幫助 -> ECS實例規格
  • ImageId: 鏡像Id, 參考ROS控製台的關鍵幫助 -> ECS鏡像
  • VpcId: 當前實例所屬的VPC
  • VSwitchId: 當前實例所屬的VSwitchId

下麵的模板將創建一個ECS的實例,本樣例中限製了實例的規格為ecs.t1.xsmallecs.t1.small, 您也可以添加 "ecs.s3.large" 到AllowedValues中,新添加一種實例的規格來創建,或者您可以直接刪除AllowedValues, 直接選用期望的實例規格

{
  "ROSTemplateFormatVersion" : "2015-09-01",
  "Description": "一個簡配的ecs實例,包括一個安全組,用戶隻需要指定imageId",
  "Parameters" : {
    "ImageId": {
      "Type" : "String",
      "Description": "鏡像文件 ID,表示啟動實例時選擇的鏡像資源"
    },
    "InstanceType": {
      "Type": "String",
      "Description": "實例的資源規格",
      "AllowedValues": [
        "ecs.t1.xsmall",
        "ecs.t1.small"
      ]
    },
    "SecurityGroupId": {
      "Type": "String",
      "Description": "安全組Id"
    }
  },
  "Resources" : {
    "WebServer": {
      "Type": "ALIYUN::ECS::Instance",
      "Properties": {
        "ImageId" : {"Ref": "ImageId"},
        "InstanceType": {"Ref": "InstanceType"},
        "SecurityGroupId": {"Ref": "SecurityGroupId"}
      }
    }
  },
  "Outputs": {
    "InstanceId": {
      "Value" : {"Fn::GetAtt": ["WebServer","InstanceId"]}
    },
    "PublicIp": {
      "Value" : {"Fn::GetAtt": ["WebServer","PublicIp"]}
    }
  }
}

最後更新:2017-04-01 13:44:33

  上一篇:go PostgreSQL full_page_write機製
  下一篇:go 陽振坤深度解析OceanBase如何支撐支付寶雙十一14萬/秒筆交易