All Products
Search
Document Center

ACS__Approve

Last Updated: Jun 11, 2020

Features

During automatic O&M, you need to pay special attention to some operations, such as deleting important resources or purchasing instances with high costs. If these operations are performed automatically, you may lose control and exceed the budget. However, if these operations are performed automatically, you need to perform them manually or in some other non-automatic ways. In this case, you can use the ACS::Approve action to strike a balance between automatic execution and operations that need special attention.

When executing an ACS::Approve action in a template, the Operation Orchestration Service (OOS) execution engine suspends the execution of the subsequent operations, sets the execution status to Waiting, and sends a notification. After receiving the notification, you can determine whether to approve or reject the operation based on the business requirements. If the operation is approved, the OOS engine continues to perform the subsequent operations. If the operation is rejected, the OOS engine stops the execution, and sets the execution status to Cancelled.

Syntax

Webhook

You can configure webhooks to send notifications to clients, such as DingTalk.

  • YAML format
  1. Tasks:
  2. - Name: approvalTask
  3. Action: ACS::Approve
  4. Properties:
  5. NotifyType: WebHook
  6. AppendExecutionLink: 'true' # Append execution link or not . ACS::Approve default option is true.
  7. WebHook:
  8. URI: url # Required. The webhook URL, such as https://oapi.dingtalk.com/robot/send?access_token=xxxxxx.
  9. Headers: # Optional. The headers of the Hypertext Transfer Protocol (HTTP) request, such as Content-Type.
  10. Content-Type: 'application/json; charset=utf-8'
  11. Content: # Required. This attribute is set based on the specific requirements of webhooks. For more information about the content of the DingTalk webhook, see https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1.
  12. msgtype: text
  13. text:
  14. content: 'the approve notify to user' # Required,the notice content to send with approve link.
  15. at: # in dingtalk group @ user when approval notice sent.
  16. atMobiles: # Optional, @ specified user in dingtalk group,the phone number is account specified user signed in with.
  17. - 138albb1234
  18. - 130albb1234
  19. isAtAll: 'false' # Optional, @ all users in dingtalk group or not, "true" or "false" optional.
  • JSON format (For more information, see the parameter description for the YAML format.)
  1. {
  2. "Tasks": [
  3. {
  4. "Name": "approvalTask",
  5. "Action": "ACS::Approve",
  6. "Properties": {
  7. "NotifyType": "WebHook",
  8. "AppendExecutionLink": "true",
  9. "WebHook": {
  10. "URI": "url",
  11. "Headers": {
  12. "Content-Type": "application/json; charset=utf-8"
  13. },
  14. "Content": {
  15. "msgtype": "text",
  16. "text": {
  17. "content": "the approve notify to user"
  18. },
  19. "at": {
  20. "atMobiles": [
  21. "138albb1234",
  22. "130albb1234"
  23. ],
  24. "isAtAll": "false"
  25. }
  26. }
  27. }
  28. }
  29. }
  30. ]
  31. }

Example

The following template is used to delete an ECS after approval:

  • YAML format
  1. FormatVersion: OOS-2019-06-01
  2. Description:
  3. en: Bulky restarts the ECS instances with Approval.
  4. name-en: BulkyRebootInstancesWithApproval
  5. Parameters:
  6. targets:
  7. Type: Json
  8. AssociationProperty: Targets
  9. AssociationPropertyMetadata:
  10. ResourceType: 'ALIYUN::ECS::Instance'
  11. rateControl:
  12. Description:
  13. en: Concurrency ratio of task execution.
  14. Type: Json
  15. AssociationProperty: RateControl
  16. Default:
  17. Mode: Concurrency
  18. MaxErrors: 0
  19. Concurrency: 100%
  20. webHookUrl:
  21. Description:
  22. en: 'The webHook url of dingtalk group assistant, e.g.https://oapi.dingtalk.com/robot/send?access_token=1234zxcvaksdq31414.'
  23. Type: String
  24. atMobiles:
  25. Description:
  26. en: 'The telephone numbers of member in dingtalk group assistant @, when notify comes.'
  27. Type: List
  28. Default:
  29. - '12345678901'
  30. atAll:
  31. Description:
  32. en: 'assistant @ all members in dingtalk group or not, when notify comes.'
  33. Type: String
  34. Default: 'false'
  35. OOSAssumeRole:
  36. Description:
  37. en: The RAM role to be assumed by OOS.
  38. Type: String
  39. Default: OOSServiceRole
  40. RamRole: '{{ OOSAssumeRole }}'
  41. Tasks:
  42. - Name: getInstance
  43. Description:
  44. en: Views the ECS instances.
  45. Action: 'ACS::SelectTargets'
  46. Properties:
  47. ResourceType: 'ALIYUN::ECS::Instance'
  48. Filters:
  49. - '{{ targets }}'
  50. Outputs:
  51. instanceIds:
  52. Type: List
  53. ValueSelector: 'Instances.Instance[].InstanceId'
  54. instanceNames:
  55. Type: List
  56. ValueSelector: 'Instances.Instance[].InstanceName'
  57. - Name: approveRestart
  58. Action: 'ACS::Approve'
  59. Properties:
  60. NotifyType: WebHook
  61. WebHook:
  62. URI: '{{webhookUrl}}'
  63. Headers:
  64. Content-Type: application/json
  65. Content:
  66. msgtype: text
  67. text:
  68. content: 'Notify: please approve instances restart, instance names to approve are {{getInstance.instanceNames}}, sent by {{ACS::RegionId}} oos {{ACS::ExecutionId}}.'
  69. at:
  70. atMobiles: '{{atMobiles}}'
  71. isAtAll: '{{atAll}}'
  72. - Name: rebootInstance
  73. Action: 'ACS::ECS::RebootInstance'
  74. Description:
  75. en: Restarts the ECS instances.
  76. Properties:
  77. instanceId: '{{ ACS::TaskLoopItem }}'
  78. Loop:
  79. RateControl: '{{ rateControl }}'
  80. Items: '{{ getInstance.instanceIds }}'
  81. Outputs:
  82. instanceIds:
  83. Type: List
  84. Value: '{{ getInstance.instanceIds }}'
  • JSON format
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Description": {
  4. "en": "Bulky restarts the ECS instances with Approval.",
  5. "name-en": "BulkyRebootInstancesWithApproval"
  6. },
  7. "Parameters": {
  8. "targets": {
  9. "Type": "Json",
  10. "AssociationProperty": "Targets",
  11. "AssociationPropertyMetadata": {
  12. "ResourceType": "ALIYUN::ECS::Instance"
  13. }
  14. },
  15. "rateControl": {
  16. "Description": {
  17. "en": "Concurrency ratio of task execution."
  18. },
  19. "Type": "Json",
  20. "AssociationProperty": "RateControl",
  21. "Default": {
  22. "Mode": "Concurrency",
  23. "MaxErrors": 0,
  24. "Concurrency": "100%"
  25. }
  26. },
  27. "webHookUrl": {
  28. "Description": {
  29. "en": "The webHook url of dingtalk group assistant, e.g.https://oapi.dingtalk.com/robot/send?access_token=1234zxcvaksdq31414."
  30. },
  31. "Type": "String"
  32. },
  33. "atMobiles": {
  34. "Description": {
  35. "en": "The telephone numbers of member in dingtalk group assistant @, when notify comes."
  36. },
  37. "Type": "List",
  38. "Default": [
  39. "12345678901"
  40. ]
  41. },
  42. "atAll": {
  43. "Description": {
  44. "en": "assistant @ all members in dingtalk group or not, when notify comes."
  45. },
  46. "Type": "String",
  47. "Default": "false"
  48. },
  49. "OOSAssumeRole": {
  50. "Description": {
  51. "en": "The RAM role to be assumed by OOS."
  52. },
  53. "Type": "String",
  54. "Default": "OOSServiceRole"
  55. }
  56. },
  57. "RamRole": "{{ OOSAssumeRole }}",
  58. "Tasks": [
  59. {
  60. "Name": "getInstance",
  61. "Description": {
  62. "en": "Views the ECS instances."
  63. },
  64. "Action": "ACS::SelectTargets",
  65. "Properties": {
  66. "ResourceType": "ALIYUN::ECS::Instance",
  67. "Filters": [
  68. "{{ targets }}"
  69. ]
  70. },
  71. "Outputs": {
  72. "instanceIds": {
  73. "Type": "List",
  74. "ValueSelector": "Instances.Instance[].InstanceId"
  75. },
  76. "instanceNames": {
  77. "Type": "List",
  78. "ValueSelector": "Instances.Instance[].InstanceName"
  79. }
  80. }
  81. },
  82. {
  83. "Name": "approveRestart",
  84. "Action": "ACS::Approve",
  85. "Properties": {
  86. "NotifyType": "WebHook",
  87. "WebHook": {
  88. "URI": "{{webhookUrl}}",
  89. "Headers": {
  90. "Content-Type": "application/json"
  91. },
  92. "Content": {
  93. "msgtype": "text",
  94. "text": {
  95. "content": "Notify: please approve instances restart, instance names to approve are {{getInstance.instanceNames}}, sent by {{ACS::RegionId}} oos {{ACS::ExecutionId}}."
  96. },
  97. "at": {
  98. "atMobiles": "{{atMobiles}}",
  99. "isAtAll": "{{atAll}}"
  100. }
  101. }
  102. }
  103. }
  104. },
  105. {
  106. "Name": "rebootInstance",
  107. "Action": "ACS::ECS::RebootInstance",
  108. "Description": {
  109. "en": "Restarts the ECS instances."
  110. },
  111. "Properties": {
  112. "instanceId": "{{ ACS::TaskLoopItem }}"
  113. },
  114. "Loop": {
  115. "RateControl": "{{ rateControl }}",
  116. "Items": "{{ getInstance.instanceIds }}"
  117. }
  118. }
  119. ],
  120. "Outputs": {
  121. "instanceIds": {
  122. "Type": "List",
  123. "Value": "{{ getInstance.instanceIds }}"
  124. }
  125. }
  126. }