全部产品
云市场

公共模版

更新时间:2019-09-27 10:04:55

我们提供了多种场景的模版供您选择,如下为当前支持的场景及模版。

公共模板

序号 名称 描述(用途) 链接
1 ACS-ECS-BulkyDeleteInstances 批量删除ECS按量付费实例。 YAML JSON
2 ACS-ECS-BulkyDeleteInstancesWithApproval 通过审批后删除ECS按量付费实例。 YAML JSON
3 ACS-ECS-BulkyDeletePrepaidInstances 批量删除ECS预付费实例。指定的ECS实例必须处于已停止状态。 YAML JSON
4 ACS-ECS-BulkyInstallLogAgent 批量在ECS实例上安装SLS代理。 YAML JSON
5 ACS-ECS-BulkyRebootInstances 批量重启ECS实例。 YAML JSON
6 ACS-ECS-BulkyRunCommand 批量在多台ECS实例上运行云助手命令。 YAML JSON
7 ACS-ECS-BulkyStartInstances 批量启动ECS实例。 YAML JSON
8 ACS-ECS-BulkyStopInstances 批量停止ECS实例。 YAML JSON
9 ACS-ECS-BulkyTagInstanceByLinuxKernelVersion 批量通过指定实例IDs将Linux内核版本用作标记值标记ECS实例。 YAML JSON
10 ACS-ECS-BulkyTagInstanceByOSType 批量通过指定实例IDs将操作系统类型用作标记值标记ECS实例。 YAML JSON
11 ACS-ECS-BulkyTagInstanceByRunCommandResult 批量根据运行云助手命令的结果标记实例。 YAML JSON
12 ACS-ECS-BulkyUpgradeInternetBandwidth 批量升级ECS实例公网带宽。 YAML JSON
13 ACS-ECS-CloneInstancesAcrossAZ 跨可用区克隆ECS实例。 YAML JSON
14 ACS-ECS-CloneInstancesAcrossRegion 跨地域克隆ECS实例。 YAML JSON
15 ACS-ECS-ConvertsPublicIPToNewEIPByInstanceId 将一台网络类型为专有网络VPC的ECS实例的公网IP转化为其它弹性公网IP。 YAML JSON
16 ACS-ECS-RunInstancesWithApproval 通过审批后创建ECS实例。 YAML JSON
17 ACS-ECS-RunRemoteShellScript 运行远端shell脚本。 YAML JSON
18 ACS-ECS-RunShellScript 运行shell脚本 YAML JSON
19 ACS-ECS-ScheduleToRebootInstances 定时重启ECS实例。 YAML JSON
20 ACS-ECS-ScheduleToStartInstances 定时启动ECS实例。 YAML JSON
21 ACS-ECS-ScheduleToStopInstances 定时停止ECS实例。 YAML JSON
22 ACS-ECS-ScheduleToUpgradeInternetBandwidth 定时升级ECS实例临时带宽。 YAML JSON
23 ACS-ECS-TagInstanceByLinuxKernelVersion 通过Linux内核版本用作标记键标记一台ECS实例。 YAML JSON
24 ACS-ECS-TagInstanceByOSType 将操作系统类型用作标记值标记一台ECS实例。 YAML JSON
25 ACS-ECS-TagInstanceByRunCommandResult 根据运行云助手命令的结果标记实例。 YAML JSON
26 ACS-ECS-UpdateImage 通过运行命令更新一个已存在的ECS镜像后创建一个新ECS镜像。 YAML JSON
27 ACS-ESS-LifeCycleModifyMongoDBIPWhitelist 根据设置MongoDB实例白名单结果修改伸缩活动的等待状态。 YAML JSON
28 ACS-ESS-LifeCycleModifyRedisIPWhitelist 根据设置Redis实例白名单结果修改伸缩活动的等待状态。 YAML JSON
29 ACS-InstallXDragonAndCloudMonitor 批量安装神龙硬件检测插件、云监控、smartmontools,以及卸载与更新神龙硬件检测插件。 YAML JSON

从实例中拷贝文件到OSS

我们经常遇到从某台线上的机器把日志文件拷贝出来或者是进程卡住了,jstack一下输出到某个文件再进行分析。我们使用osscmd把数据导到oss里,但是手动配置过程实在是过于繁琐。通过如下模版您可很容易地处理此需求。
模版内容(JSON格式):

  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": "Tag ECS Instance by the RunCommand invocation result.",
  4. "Parameters": {
  5. "InstanceId": {
  6. "Type": "String",
  7. "Description": "the Instance Id to operate in linux.",
  8. "MinLength": 1,
  9. "MaxLength": 30
  10. },
  11. "SrcUrl": {
  12. "Type": "String",
  13. "Description": "command content to run in linux ecs."
  14. },
  15. "DestUrl": {
  16. "Type": "String",
  17. "Description": "command content to run in linux ecs."
  18. },
  19. "InstanceAssumeRole": {
  20. "Type": "String",
  21. "Description": ""
  22. },
  23. "OOSAssumeRole": {
  24. "Type": "String",
  25. "Description": "oos assume this role to execution task.",
  26. "Default": "OOSServiceRole"
  27. }
  28. },
  29. "RamRole": "{{OOSAssumeRole}}",
  30. "Tasks": [{
  31. "Name": "checkInstanceReady",
  32. "Action": "ACS::CheckFor",
  33. "Description": "describe instances",
  34. "Properties": {
  35. "API": "DescribeInstances",
  36. "Service": "ECS",
  37. "PropertySelector": "Instances.Instance[].Status",
  38. "DesiredValues": [
  39. "Running"
  40. ],
  41. "Parameters": {
  42. "InstanceIds": ["{{ InstanceId }}"]
  43. }
  44. }
  45. },
  46. {
  47. "Name": "runCommand",
  48. "Action": "ACS::ECS::RunCommand",
  49. "Description": "",
  50. "Properties": {
  51. "commandContent": {
  52. "Fn::Join": [ "\n", [
  53. "test -e oos || mkdir oos;",
  54. "cd oos;",
  55. "test -e ossutil64 || wget https://oos-public.oss-{{ACS::RegionId}}-internal.aliyuncs.com/x64/ossutil64 && chmod 755 ossutil64",
  56. "test -e jq || wget https://oos-public.oss-{{ACS::RegionId}}-internal.aliyuncs.com/x64/jq && chmod 755 jq",
  57. "stsToken=`curl http://100.100.100.200/latest/meta-data/Ram/security-credentials/{{InstanceAssumeRole}}`",
  58. "accessKeyId=`echo $stsToken |./jq .AccessKeyId | awk -F'\"' '{print $2}'` ;",
  59. "accessKeySecret=`echo $stsToken | ./jq .AccessKeySecret | awk -F'\"' '{print $2}'` ;",
  60. "securityToken=`echo $stsToken | ./jq .SecurityToken | awk -F'\"' '{print $2}'` ;",
  61. "endpoint=https://oss-{{ACS::RegionId}}-internal.aliyuncs.com;",
  62. "./ossutil64 -i $accessKeyId -k $accessKeySecret -t $securityToken -e $endpoint cp {{SrcUrl}} {{DestUrl}}"
  63. ]
  64. ]
  65. },
  66. "commandType": "RunShellScript",
  67. "instanceId": "{{InstanceId}}"
  68. },
  69. "Outputs": {
  70. "CommandOutput":{
  71. "Type": "String",
  72. "ValueSelector": "InvocationResult[].Output"
  73. }
  74. }
  75. }
  76. ],
  77. "Outputs": {}
  78. }

给ECS实例自动打TAG

对于一般的资源管理需求,都是资源数量较多的情况,如当实例的数量较多时,对实例进行运维管理等操作就会变得比较困难,有时候甚至需要采取拆分账号的方式管理不同部门或者不同用途的资源。如果采用Tag进行资源的分类管理,会提供极大便利。

我们可以针对实例的使用场景进行分类打Tag,在一般的开发场景中,机器一般有多个分类:开发测试环境、打包环境、生产环境等。这些机器的运维管理是绝对隔绝的,因此要在Tag上对其进行区分,在开发测试机器上,可以增加标签(增加方式详见下一节)key为env、value为test;在生产机器上,可以增加标签key为env、value为product。形成类似如下图的机器分类。oos

我们也可按kernelVersion,osType等场景分类来打Tag,osType分为linux、window等。 kernerlVersion 为uname -r的返回结果。以下模版可助您快速地按osType进行打标签。

模版内容(JSON格式):

  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": "tag instance by os type",
  4. "Parameters": {
  5. "InstanceId": {
  6. "Type": "String",
  7. "Description": "the InstanceId to tag",
  8. "MinLength": 1,
  9. "MaxLength": 30
  10. },
  11. "TagKey": {
  12. "Type": "String",
  13. "Description": "the tag key you specified"
  14. },
  15. "OOSAssumeRole": {
  16. "Type": "String",
  17. "Description": "The RAM role to be assumed by OOS.",
  18. "Default": "OOSServiceRole"
  19. }
  20. },
  21. "RamRole": "{{OOSAssumeRole}}",
  22. "Tasks": [
  23. {
  24. "Name": "queryInstanceOsType",
  25. "Action": "ACS::ExecuteApi",
  26. "Description": "",
  27. "Properties": {
  28. "API": "DescribeInstances",
  29. "Service": "ECS",
  30. "Parameters": {
  31. "InstanceIds": [
  32. "{{ InstanceId }}"
  33. ]
  34. }
  35. },
  36. "Outputs": {
  37. "OsType": {
  38. "ValueSelector": "Instances.Instance[].OSType",
  39. "Type": "String"
  40. }
  41. }
  42. },
  43. {
  44. "Name": "tagResources",
  45. "Action": "ACS::ExecuteApi",
  46. "Description": "Tag Resources.",
  47. "Properties": {
  48. "API": "TagResources",
  49. "Service": "ECS",
  50. "Parameters": {
  51. "ResourceType": "Instance",
  52. "ResourceIds": [
  53. "{{ InstanceId }}"
  54. ],
  55. "Tags": [
  56. {
  57. "Key": "{{ TagKey }}",
  58. "Value": "{{ queryInstanceOsType.OsType }}"
  59. }
  60. ]
  61. }
  62. }
  63. }
  64. ],
  65. "Outputs": {
  66. "OsType": {
  67. "Type": "String",
  68. "Value": "{{ queryInstanceOsType.OsType}}"
  69. }
  70. }
  71. }

给实例加到SLS机器组

我们经常遇到以下场景,扩容一批机器需要配置SLS日志,对于已经配置好的SLS Logstore,我们只需要将机器加到机器组里。通过如下模版可助您轻松完成此操作。

模版内容(JSON格式):

  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": "Install Logtail agent on the ECS Instance.",
  4. "Parameters": {
  5. "InstanceId": {
  6. "Type": "String",
  7. "Description": "the Instance Id to install ilogtail",
  8. "AllowedPattern": "i-[A-Za-z0-9]*",
  9. "MinLength": 1,
  10. "MaxLength": 30
  11. },
  12. "LogTailUserDefinedId": {
  13. "Type": "String",
  14. "Description": "the user defined Id write to /etc/ilogtail/user_defined_id",
  15. "AllowedPattern": "[A-Za-z0-9\\-_]*",
  16. "MinLength": 1,
  17. "MaxLength": 30
  18. },
  19. "OOSAssumeRole": {
  20. "Type": "String",
  21. "Description": "The RAM role to be assumed by OOS.",
  22. "Default": "OOSServiceRole"
  23. }
  24. },
  25. "RamRole": "{{OOSAssumeRole}}",
  26. "Tasks": [
  27. {
  28. "Name": "checkInstanceReady",
  29. "Action": "ACS::CheckFor",
  30. "Description": "describe instances.",
  31. "Properties": {
  32. "API": "DescribeInstances",
  33. "Service": "ECS",
  34. "PropertySelector": "Instances.Instance[].Status",
  35. "DesiredValues": [
  36. "Running"
  37. ],
  38. "Parameters": {
  39. "InstanceIds": [
  40. "{{ InstanceId }}"
  41. ]
  42. }
  43. },
  44. "Outputs": {
  45. "InstanceIds": {
  46. "ValueSelector": "InstanceIdSets.InstanceIdSet[]",
  47. "Type": "List"
  48. }
  49. }
  50. },
  51. {
  52. "Name": "createCommand",
  53. "Action": "ACS::ExecuteApi",
  54. "Description": "create the command to install logtail agent.",
  55. "Properties": {
  56. "API": "CreateCommand",
  57. "Service": "ECS",
  58. "Parameters": {
  59. "CommandContent": {
  60. "Fn::Base64Encode": "wget http://logtail-release-{{ACS::RegionId}}.oss-{{ACS::RegionId}}-internal.aliyuncs.com/linux64/logtail.sh -O logtail.sh; chmod 755 logtail.sh; ./logtail.sh install {{ACS::RegionId}}; echo {{ LogTailUserDefinedId }} > /etc/ilogtail/user_defined_id"
  61. },
  62. "Name": "oos-{{ACS::TemplateName}}",
  63. "Type": "RunShellScript"
  64. }
  65. },
  66. "Outputs": {
  67. "CommandId": {
  68. "Type": "String",
  69. "ValueSelector": "CommandId"
  70. }
  71. }
  72. },
  73. {
  74. "Name": "invokeCommand",
  75. "Action": "ACS::ExecuteApi",
  76. "Description": "invoke the command to install ilogtail",
  77. "Properties": {
  78. "Service": "ECS",
  79. "API": "InvokeCommand",
  80. "Parameters": {
  81. "CommandId": "{{ createCommand.CommandId }}",
  82. "InstanceIds": [
  83. "{{ InstanceId }}"
  84. ]
  85. }
  86. },
  87. "Outputs": {
  88. "InvokeId": {
  89. "Type": "String",
  90. "ValueSelector": "InvokeId"
  91. }
  92. }
  93. },
  94. {
  95. "Name": "untilInvocationDone",
  96. "Action": "ACS::WaitFor",
  97. "Description": "until invocation ready",
  98. "MaxAttempts": 5,
  99. "Properties": {
  100. "Service": "ECS",
  101. "API": "DescribeInvocations",
  102. "Parameters": {
  103. "InvokeId": "{{ invokeCommand.InvokeId }}"
  104. },
  105. "DesiredValues": [
  106. "Finished"
  107. ],
  108. "PropertySelector": "Invocations.Invocation[].InvokeStatus"
  109. }
  110. },
  111. {
  112. "Name": "describeInvocationResult",
  113. "Action": "ACS::ExecuteApi",
  114. "Description": "get the command invocation result",
  115. "Properties": {
  116. "Service": "Ecs",
  117. "API": "DescribeInvocationResults",
  118. "Parameters": {
  119. "InvokeId": "{{ invokeCommand.InvokeId }}"
  120. }
  121. },
  122. "Outputs": {
  123. "InvocationResult": {
  124. "Type": "String",
  125. "ValueSelector": "Invocation.InvocationResults.InvocationResult[].Output"
  126. },
  127. "ExitCode": {
  128. "Type": "Number",
  129. "ValueSelector": "Invocation.InvocationResults.InvocationResult[].ExitCode"
  130. }
  131. }
  132. },
  133. {
  134. "Name": "deleteCommand",
  135. "Action": "ACS::ExecuteAPI",
  136. "Description": "clean up the install ilogtail command",
  137. "Properties": {
  138. "Service": "ECS",
  139. "Risk": "Normal",
  140. "API": "DeleteCommand",
  141. "Parameters": {
  142. "CommandId": "{{ createCommand.CommandId }}"
  143. }
  144. }
  145. }
  146. ],
  147. "Outputs": {
  148. "InvocationResult": {
  149. "Type": "String",
  150. "Value": {
  151. "Fn::Base64Decode": "{{ describeInvocationResult.InvocationResult }}"
  152. }
  153. },
  154. "ExitCode": {
  155. "Type": "String",
  156. "Value": "{{ describeInvocationResult.ExitCode }}"
  157. }
  158. }
  159. }