All Products
Search
Document Center

CloudOps Orchestration Service:ACS::Notify

Last Updated:Mar 21, 2024

Description

The ACS::Notify action notifies you when an O&M task is complete. For example, after you purchase an Elastic Compute Service (ECS) instance, you can receive a DingTalk notification to view the bill in real time.

Syntax

ACS::Notify supports webhook and email notifications. You can use the following syntax to configure webhook and email notifications.

Webhook

  • YAML format

Tasks:
  - Name: notifyTask
    Action: ACS::Notify
    Properties:
      NotifyType: WebHook
          AppendExecutionLink: 'false' # Specifies whether to append execution links. Valid values: true and false. Default value: false. 
      WebHook:
        URI: url # Required. The webhook URL. Example: https://oapi.dingtalk.com/robot/send?access_token=xxxxxx.
        Headers: # Optional. The headers of the HTTP request. Example: Content-Type.
          Content-Type: 'application/json; charset=utf-8'
        Content: # Required. The content of the webhook notification. Set the value based on the requirements for the webhook. For information about the content of the DingTalk webhook, visit https://open-doc.dingtalk.com/docs/doc.htm?treeId=257&articleId=105735&docType=1. 
          msgtype: text
          text: 
            content: 'this is a dingtalk message with a parameter {{ p1 }}'
  • JSON format (For more information, see the attribute descriptions for the YAML format.)

{
  "Tasks": [
    {
      "Name": "notifyTask",
      "Action": "ACS::Notify",
      "Properties": {
        "NotifyType": "WebHook",
        "AppendExecutionLink": "false",
        "WebHook": {
          "URI": "url",
          "Headers": {
            "Content-Type": "application/json; charset=utf-8"
          },
          "Content": {
            "msgtype": "text",
            "text": {
              "content": "this is a dingtalk message with a parameter {{ p1 }}"
            }
          }
        }
      }
    }
  ]
}

Email

  • YAML format

Tasks:
  - Action: ACS::Notify
    Name: testNotifyByMail
    Properties:
        NotifyType: Mail
        Mail:
                Host: SMTPHostAddress # The Simple Mail Transfer Protocol (SMTP) server address. Example: smtp.example1.com.
            Port: SMTPPort # The port number of the SMTP server. Example: 465.
            Username: sender  # The email account that is used to send the notification. Example: usr001@example1.com.
            Password: senderPassword # The password of the email account that is used to send the notification. Example: 123456zxcv.
            Subject: mailSubject # The subject of the email notification. Example: hello world.
            Body: mailBody # The body of the email notification. Example: hello world!!!   
            From: senderAddress # The email address of the sender. Example: usr001@example1.com.
            To:  receiverAddresses        # The email addresses of the recipients. Example: [usr1234@example2.com,usr123@example2.com].
  • JSON format (For more information, see the attribute descriptions for the YAML format.)

{
  "Tasks": [
    {
      "Action": "ACS::Notify",
      "Name": "testNotifyByMail",
      "Properties": {
        "NotifyType": "Mail",
        "Mail": {
          "Host": "SMTPHostAddress",
          "Port": "SMTPPort",
          "Username": "sender",
          "Password": "senderPassword",
          "Subject": "mailSubject",
          "Body": "mailBody",
          "From": "senderAddress",
          "To": "receiverAddresses"
        }
      }
    }
  ]
}

Examples

  • YAML format

---
FormatVersion: OOS-2019-06-01
Outputs:
    InstanceIds:
        Type: List
        Value: ' {{ runInstances.InstanceIds }} '
Parameters:
    ImageId:
        Description: the image id for the new instances.
        Type: String
    InstanceType:
        Description: the Instance Type for the new instances.
        Type: String
    OOSAssumeRole:
        Default: OOSServiceRole
        Description: oos assume this role to execution task
        Type: String
    SecurityGroupId:
        Description: the security group id for the new instances.
        Type: String
    VSwitchId:
        Description: the virtual switch id for the new instances.
        Type: String
RamRole: '{{OOSAssumeRole}}'
Tasks:
-   Action: ACS::ExecuteAPI
    Description: 'run instances with specified parameters'
    Name: runInstances
    Outputs:
        InstanceIds:
            Type: List
            ValueSelector: .InstanceIdSets.InstanceIdSet[]
    Properties:
        API: RunInstances
        Parameters:
            ImageId: '{{ ImageId }}'
            InstanceType: '{{ InstanceType }}'
            SecurityGroupId: '{{ SecurityGroupId }}'
            VSwitchId: '{{ VSwitchId }}'
        Service: ECS
-   Action: ACS::Notify
    Name: test_notify
    Properties:
        NotifyType: WebHook
        WebHook:
            Content:
                msgtype: text
                text: 
                        content: 
            Headers:
                Content-Type: application/json
            URI: https://oapi.dingtalk.com/robot/send?access_token=your_access_token
  • JSON format

{
    "FormatVersion": "OOS-2019-06-01",
    "Outputs": {
        "InstanceIds": {
            "Type": "List"
            "Value": " {{ runInstances.InstanceIds }} "
        }
    },
    "Parameters": {
        "ImageId": {
            "Description": "the image id for the new instances.",
            "Type": "String"
        },
        "InstanceType": {
            "Description": "the Instance Type for the new instances.",
            "Type": "String"
        },
        "SecurityGroupId": {
            "Description": "the security group id for the new instances.",
            "Type": "String"
        },
        "VSwitchId": {
            "Description": "the virtual switch id for the new instances.",
            "Type": "String"
        },
          "OOSAssumeRole": {
                      "Type": "String",
                      "Description":  "oos assume this role to execution task",
                      "Default": "OOSServiceRole"
    }
    },
    "RamRole": "{{OOSAssumeRole}}",
    "Tasks": [
        {
            "Action": "ACS::ExecuteAPI",
            "Description": "run instances with specified parametersl",
            "Name": "runInstances",
            "Outputs": {
                "InstanceIds": {
                    "Type": "List",
                    "ValueSelector": ".InstanceIdSets.InstanceIdSet[]"
                }
            },
            "Properties": {
                "API": "RunInstances",
                "Parameters": {
                    "ImageId": "{{ ImageId }}",
                    "InstanceType": "{{ InstanceType }}",
                    "SecurityGroupId": "{{ SecurityGroupId }}",
                    "VSwitchId": "{{ VSwitchId }}"
                },
                "Service": "ECS"
            }
        },
       {
      "Name": "test_notify",
      "Action": "ACS::Notify",
      "Properties": {
        "NotifyType": "WebHook",
        "WebHook": {
          "URI": "https://oapi.dingtalk.com/robot/send?access_token=your_access_token",
          "Headers": {
            "Content-Type": "application/json"
          },
          "Content": {
            "msgtype": "text",
            "text": {
              "content":"test"
            }
          }
        }
      }
    } 
    ]
}