All Products
Search
Document Center

Operation Orchestration Service:Public Templates

Last Updated:Jun 14, 2021

Operation Orchestration Service (OOS) provides various public templates specific to different scenarios. The following tables list the currently supported templates and the sample code.

Handle multiple O&M tasks at a time

Template Description Sample code
ACS-ECS-StartInstancesByInstanceIds Starts the ECS instances that have the specified IDs at the same time. When this template is executed, the StartInstance operation is called to start the ECS instances. Only ECS instances in the Stopped status can be started. Required parameter: instanceIds. YAML
ACS-ECS-StopInstancesByInstanceIds Stops the ECS instances that have the specified IDs at the same time. When this template is executed, the StopInstance operation is called to stop the ECS instances. Only ECS instances in the Running status can be stopped. Required parameter: instanceIds. YAML
ACS-ECS-RebootInstancesByInstanceIds Restarts the ECS instances that have the specified IDs at the same time. When this template is executed, the RebootInstance operation is called to restart the ECS instances. Only ECS instances in the Running status can be restarted. Required parameter: instanceIds. YAML
ACS-ECS-ScheduleToUpgradeInternetBandwidthByInstanceIds Temporarily upgrades the bandwidth for the ECS instances that have the specified IDs at the specified point in time. When this template is executed, the ModifyInstanceNetworkSpec operation is called to temporarily upgrade the bandwidth for the ECS instances that have the specified IDs at the specified point in time. Required parameters: cron, endDate, instanceIds, maxBandwidthIn, maxBandwidthOut, startTime, and endTime. YAML
ACS-ECS-BulkyUpgradeInternetBandwidthByInstanceIds Temporarily upgrades the bandwidth for the ECS instances that have the specified IDs at the same time. When this template is executed, the ModifyInstanceNetworkSpec operation is called to temporarily upgrade the bandwidth for the ECS instances that have the specified IDs. Required parameters: instanceIds, maxBandwidthIn, maxBandwidthOut, startTime, and endTime. YAML
ACS-ECS-BulkyDeletePrepaidInstanceByInstanceIds Releases the subscription-based ECS instances that have the specified IDs at the same time. Required parameter: instanceIds. YAML
ACS-ECS-BulkyRunCommandByTag Runs a command in the Cloud Assistant client on multiple ECS instances that are specified by instance tags. Required parameters: tagKey, tagValue, commandContent, and commandType. YAML
ACS-ECS-BulkyTagInstanceByRunCommandResultAndInstanceIds Creates a tag and attaches it to the specified ECS instances based on the results returned by running a command in the Cloud Assistant client. Required parameters: instanceIds, tagKey, and commandContent. YAML
ACS-ECS-BulkyTagInstanceByOSTypeAndInstanceIds Creates a tag and attaches it to the specified ECS instances based on the operating system types of the instances. Required parameters: instanceIds and tagKey. YAML
ACS-ECS-BulkyTagInstanceByLinuxKernelVersionAndInstanceIds Creates a tag and attaches it to the specified ECS instances based on the Linux kernel versions of the instances. Required parameters: instanceIds and tagKey. YAML

Update images

To ensure secure running of the ECS instances, you may need to deploy patches or upgrade the components that the ECS instances depend on. Generally, the operations start from updating the source image and end in generating a new image for testing and production. Before updating an image, you need to use the source image to create an instance. After the update completes, the instance must be released. The update process is complicated. Therefore, OOS provides you with the ACS-ECS-UpdateImage template to process such update requests conveniently.

Template Description Sample code
ACS-ECS-UpdateImage Automatically updates an ECS image based on the following logic: Create an ECS instance from the source image, run a command in the Cloud Assistant client to create an ECS image from this instance, and then release the instance. Required parameters: sourceImageId, instanceType, securityGroupId, vSwitchId, commandContent, commandType, and targetImageName. YAML

Manage approval requests

Template Description Sample code
ACS-ECS-DeleteInstancesWithApprovalByInstanceIds Releases the ECS instances that have been approved through DingTalk at the same time. Required parameters: instanceIds and accessToken. YAML
ACS-ECS-BuyCostlyInstancesWithApproval Creates ECS instances with a DingTalk approval. When this template is executed, OOS sends an approval notification to the specified DingTalk contact or group and creates ECS instances with the approval by the contact or group. Required parameters: accessToken, imageId, instanceType, securityGroupId, vSwitchId, and amount. YAML

Manage scheduled tasks

Template Description Sample code
ACS-ECS-ScheduleToStopInstancesByTag Stops the ECS instances that have the specified tag at the specified point in time. When this template is executed, the StopInstance operation is called to stop the ECS instances that have the specified tag at the specified point in time. Only ECS instances in the Running status can be stopped. Required parameters: cron, endDate, tagKey, and tagValue. YAML
ACS-ECS-ScheduleToStartInstancesByTag Starts the ECS instances that have the specified tag at the specified point in time. When this template is executed, the StartInstance operation is called to start the ECS instances that have the specified tag at the specified point in time. Only ECS instances in the Stopped status can be started. Required parameters: cron, endDate, tagKey, and tagValue. YAML
ACS-ECS-ScheduleToRebootInstancesByTag Restarts the ECS instances that have the specified tag at the specified point in time. When this template is executed, the RebootInstance operation is called to restart the ECS instances that have the specified tag at the specified point in time. Only ECS instances in the Running status can be restarted. Required parameters: cron, endDate, tagKey, and tagValue. YAML
ACS-ECS-ScheduleToUpgradeInternetBandwidthByInstanceIds Temporarily upgrades the bandwidth for the ECS instances that have the specified IDs at the specified point in time. When this template is executed, the ModifyInstanceNetworkSpec operation is called to temporarily upgrade the bandwidth for the ECS instances that have the specified IDs at the specified point in time. Required parameters: cron, endDate, instanceIds, maxBandwidthIn, maxBandwidthOut, startTime, and endTime. YAML

Manage O&M tasks based on tags

Template Description Sample code
ACS-ECS-ScheduleToStopInstancesByTag Stops the ECS instances that have the specified tag at the specified point in time. When this template is executed, the StopInstance operation is called to stop the ECS instances that have the specified tag at the specified point in time. Only ECS instances in the Running status can be stopped. Required parameters: cron, endDate, tagKey, and tagValue. YAML
ACS-ECS-RebootInstancesByTag Restarts the ECS instances that have the specified tags at the same time. When this template is executed, the RebootInstance operation is called to restart the ECS instances that have the specified tag. Only ECS instances in the Running status can be restarted. Required parameters: tagKey and tagValue. YAML
ACS-ECS-StartInstancesByTag Starts the ECS instances that have the specified tags at the same time. When this template is executed, the StartInstance operation is called to start the ECS instances that have the specified tag. Only ECS instances in the Stopped status can be started. Required parameters: tagKey and tagValue. YAML

Manage standardized O&M tasks

Template Description Sample code
ACS-ECS-TagInstanceByRunCommandResult Runs a command in the Cloud Assistant client on the specified ECS instance, creates a tag, and attaches the tag to the instance based on the command output. Required parameters: instanceId, tagKey, and commandContent. YAML
ACS-ECS-TagInstanceByLinuxKernelVersion Creates a tag and attaches it to the specified ECS instance based on the Linux kernel version of the instance. Required parameters: instanceId and tagKey. YAML
ACS-ECS-TagInstanceByOSType Creates a tag and attaches it to the specified ECS instance based on the operating system type of the instance. Required parameters: instanceId and tagKey. YAML

Manage cross-region O&M tasks

Template Description Sample code
ACS-ECS-CloneInstancesAcrossAZ Duplicates multiple ECS instances with the same specifications across zones at a time. Procedure: Obtain the specifications of the ECS instances to be duplicated and create the images of the instances. After the images are created, use the images to create ECS instances with the same specifications as the duplicated ones, and then run the instances in the target zone. Required parameters: instanceIds, regionId, targetZoneId, targetSecurityGroupId, and targetVSwitchId. YAML
ACS-ECS-CloneInstancesAcrossRegion Duplicates multiple ECS instances across regions at a time. Procedure: Create the images of the ECS instances to be duplicated. After the images are created, duplicate the images to the target region, create ECS instances based on the images, and then run the instances in the target zone of the target region. Required parameters: instanceIds, regionId, targetRegionId, targetZoneId, targetInstanceType, targetSecurityGroupId, and targetVSwitchId. YAML

Replicate files from ECS instances to OSS buckets

You can use the osscmd tool to replicate log files from ECS instances to OSS buckets or store the output of jstack to a file in an OSS bucket for problem analysis when a process is stuck. The manual operation is complicated. In this case, you can use the following template to process the request.
Template (JSON format):

  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. }

Attach tags to ECS instances

O&M is difficult where there are a large number of instances. Sometimes, you need to use several accounts to manage the instances in different departments or of different purposes. In this case, we recommend that you manage instances based on tags.

You can attach tags to instances based on scenarios. For example, instances are grouped for different environments, including the development and testing, staging, and production environments. The O&M operations for these instances are isolated. You can attach tags to distinguish these instances. For example, you can attach the tag of which the key is env and the value is test to the instances in the development and testing environment, and add the tag of which the key is env and the value is product to the instances in the production environment. The following figure shows an example of how to group the instances.OOS

You can also attach tags to instances based on the kernel version and operating system type. For example, you can group instances based on the operating system type, such as Linux and Window. You can obtain the kernel version by running the uname -r command. The following template is used to attach tags to instances based on the operating system type:

Template (JSON format):

  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. }

Add instances to Log Service machine groups

Before multiple instances are resized, you need to configure Log Service for the instances. After a Logstore is created, you can add the instances to a Log Service machine group. You can use the following template to add the instance to the Logstore instance group.

Template (JSON format):

  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. }