全部产品
云市场

通知ACS::Notify

更新时间:2019-08-21 15:14:50

用途

该动作可以用在运维任务完成后用户需要被告知的场景。如在购买ECS实例完成以后,发送一个钉钉通知便于您对账单有实时的了解。

语法

当前支持Webhook和Mail两种通知类型,定义方式如下。

Webhook

  • YAML格式
  1. Tasks:
  2. - Name: notifyTask
  3. Type: ACS::Notify
  4. Properties:
  5. NotifyType: WebHook
  6. WebHook:
  7. URI: url # 必填,webhook地址,如https://oapi.dingtalk.com/robot/send?access_token=xxxxxx
  8. Headers: # 可选,Http请求的Headers,如Content-Type
  9. Content-Type: 'application/json; charset=utf-8'
  10. Content: # 必填,根据具体的Webhook要求提供,如钉钉webhook要求如下:https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1
  11. msgtype: text
  12. text:
  13. content: 'this is a dingtalk message with a parameter {{ p1 }}'
  • JSON格式(请参照YAML注释说明)
  1. {
  2. "Tasks": [
  3. {
  4. "Name": "notifyTask",
  5. "Type": "ACS::Notify",
  6. "Properties": {
  7. "NotifyType": "WebHook",
  8. "WebHook": {
  9. "URI": "url",
  10. "Headers": {
  11. "Content-Type": "application/json; charset=utf-8"
  12. },
  13. "Content": {
  14. "msgtype": "text",
  15. "text": {
  16. "content": "this is a dingtalk message with a parameter {{ p1 }}"
  17. }
  18. }
  19. }
  20. }
  21. }
  22. ]
  23. }

Mail

  • YAML格式
  1. Tasks:
  2. - Action: ACS::Notify
  3. Name: testNotifyByMail
  4. Properties:
  5. NotifyType: Mail
  6. Mail:
  7. Host: SMTPHostAddress # SMTP 服务器主机地址 如 smtp.example1.com
  8. Port: SMTPPort # SMTP 服务器端口 如 465
  9. Username: sender # 代发送的邮箱用户 如 usr001@example1.com
  10. Password: senderPassword # 代发送的邮箱密码 如 123456zxcv
  11. Subject: mailSubject # 邮件主题 如 hello world
  12. Body: mailBody # 邮件正文 如 hello world !!!
  13. From: senderAddress # 邮件来自 如 usr001@example1.com
  14. To: receiverAddresses # 收件人邮箱地址列表 如 [usr1234@example2.com,usr123@example2.com]
  • JSON格式(请参照YAML注释说明)
  1. {
  2. "Tasks": [
  3. {
  4. "Action": "ACS::Notify",
  5. "Name": "testNotifyByMail",
  6. "Properties": {
  7. "NotifyType": "Mail",
  8. "Mail": {
  9. "Host": "SMTPHostAddress",
  10. "Port": "SMTPPort",
  11. "Username": "sender",
  12. "Password": "senderPassword",
  13. "Subject": "mailSubject",
  14. "Body": "mailBody",
  15. "From": "senderAddress",
  16. "To": "receiverAddresses"
  17. }
  18. }
  19. }
  20. ]
  21. }

示例

  • YAML格式:
  1. ---
  2. FormatVersion: OOS-2019-06-01
  3. Outputs:
  4. InstanceIds:
  5. Type: List
  6. Value: ' {{ runInstances.InstanceIds }} '
  7. Parameters:
  8. ImageId:
  9. Description: the image id for the new instances.
  10. Type: String
  11. InstanceType:
  12. Description: the Instance Type for the new instances.
  13. Type: String
  14. OOSAssumeRole:
  15. Default: OOSServiceRole
  16. Description: oos assume this role to execution task
  17. Type: String
  18. SecurityGroupId:
  19. Description: the security group id for the new instances.
  20. Type: String
  21. VSwitchId:
  22. Description: the virtual switch id for the new instances.
  23. Type: String
  24. RamRole: '{{OOSAssumeRole}}'
  25. Tasks:
  26. - Action: ACS::ExecuteAPI
  27. Description: 'run instances with specified parameters, refer them here: https://help.aliyun.com/document_detail/63440.html'
  28. Name: runInstances
  29. Outputs:
  30. InstanceIds:
  31. Type: List
  32. ValueSelector: .InstanceIdSets.InstanceIdSet[]
  33. Properties:
  34. API: RunInstances
  35. Parameters:
  36. ImageId: '{{ ImageId }}'
  37. InstanceType: '{{ InstanceType }}'
  38. SecurityGroupId: '{{ SecurityGroupId }}'
  39. VSwitchId: '{{ VSwitchId }}'
  40. Service: ECS
  41. - Action: ACS::Notify
  42. Name: test_notify
  43. Properties:
  44. NotifyType: WebHook
  45. WebHook:
  46. Content:
  47. msgtype: text
  48. text:
  49. content:
  50. Headers:
  51. Content-Type: application/json
  52. URI: https://oapi.dingtalk.com/robot/send?access_token=your_access_token
  • JSON格式:
  1. {
  2. "FormatVersion": "OOS-2019-06-01",
  3. "Outputs": {
  4. "InstanceIds": {
  5. "Type": "List"
  6. "Value": " {{ runInstances.InstanceIds }} "
  7. }
  8. },
  9. "Parameters": {
  10. "ImageId": {
  11. "Description": "the image id for the new instances.",
  12. "Type": "String"
  13. },
  14. "InstanceType": {
  15. "Description": "the Instance Type for the new instances.",
  16. "Type": "String"
  17. },
  18. "SecurityGroupId": {
  19. "Description": "the security group id for the new instances.",
  20. "Type": "String"
  21. },
  22. "VSwitchId": {
  23. "Description": "the virtual switch id for the new instances.",
  24. "Type": "String"
  25. },
  26. "OOSAssumeRole": {
  27. "Type": "String",
  28. "Description": "oos assume this role to execution task",
  29. "Default": "OOSServiceRole"
  30. }
  31. },
  32. "RamRole": "{{OOSAssumeRole}}",
  33. "Tasks": [
  34. {
  35. "Action": "ACS::ExecuteAPI",
  36. "Description": "run instances with specified parameters, refer them here: https://help.aliyun.com/document_detail/63440.html",
  37. "Name": "runInstances",
  38. "Outputs": {
  39. "InstanceIds": {
  40. "Type": "List",
  41. "ValueSelector": ".InstanceIdSets.InstanceIdSet[]"
  42. }
  43. },
  44. "Properties": {
  45. "API": "RunInstances",
  46. "Parameters": {
  47. "ImageId": "{{ ImageId }}",
  48. "InstanceType": "{{ InstanceType }}",
  49. "SecurityGroupId": "{{ SecurityGroupId }}",
  50. "VSwitchId": "{{ VSwitchId }}"
  51. },
  52. "Service": "ECS"
  53. }
  54. },
  55. {
  56. "Name": "test_notify",
  57. "Action": "ACS::Notify",
  58. "Properties": {
  59. "NotifyType": "WebHook",
  60. "WebHook": {
  61. "URI": "https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
  62. "Headers": {
  63. "Content-Type": "application/json"
  64. },
  65. "Content": {
  66. "msgtype": "text",
  67. "text": {
  68. "content":"test"
  69. }
  70. }
  71. }
  72. }
  73. }
  74. ]
  75. }