説明
ACS::Notify アクションは、O&M タスクの完了時に通知します。たとえば、Elastic Compute Service(ECS)インスタンスを購入した後、DingTalk 通知が送信され、リアルタイムで請求額を確認できます。
構文
ACS::Notify は、Webhook 通知とメール通知をサポートしています。 Webhook 通知とメール通知を設定するには、次の構文を使用できます。
Webhook
Tasks:
- Name: notifyTask
Action: ACS::Notify
Properties:
NotifyType: WebHook
AppendExecutionLink: 'false' # 実行リンクを追加するかどうかを指定します。有効な値:true および false。デフォルト値:false。
WebHook:
URI: url # 必須。Webhook URL。例:https://oapi.dingtalk.com/robot/send?access_token=xxxxxx。
Headers: # オプション。HTTP リクエストのヘッダー。例:Content-Type。
Content-Type: 'application/json; charset=utf-8'
Content: # 必須。Webhook 通知の内容。Webhook の要件に基づいて値を設定します。DingTalk Webhook の内容については、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 }}'
{
"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 }}"
}
}
}
}
}
]
}
メール
Tasks:
- Action: ACS::Notify
Name: NotifyByMail
Properties:
NotifyType: Mail
Mail:
Host: SMTPHostAddress # 簡易メール転送プロトコル(SMTP)サーバーアドレス。例:smtp.example1.com。
Port: SMTPPort # SMTP サーバーのポート番号。例:465。
Username: sender # 通知の送信に使用するメールアカウント。例:usr001@example1.com。
Password: senderPassword # 通知の送信に使用するメールアカウントのパスワード。例:123456zxcv。
Subject: mailSubject # メール通知の件名。例:hello world。
Body: mailBody # メール通知の本文。例:hello world!!!
From: senderAddress # 送信者のメールアドレス。例:usr001@example1.com。
To: receiverAddresses # 受信者のメールアドレス。例:[usr1234@example2.com,usr123@example2.com]。
{
"Tasks": [
{
"Action": "ACS::Notify",
"Name": "NotifyByMail",
"Properties": {
"NotifyType": "Mail",
"Mail": {
"Host": "SMTPHostAddress",
"Port": "SMTPPort",
"Username": "sender",
"Password": "senderPassword",
"Subject": "mailSubject",
"Body": "mailBody",
"From": "senderAddress",
"To": "receiverAddresses"
}
}
}
]
}
例
---
FormatVersion: OOS-2019-06-01
Outputs:
InstanceIds:
Type: List
Value: ' {{ runInstances.InstanceIds }} '
Parameters:
ImageId:
Description: 新しいインスタンスのイメージ ID。
Type: String
InstanceType:
Description: 新しいインスタンスのインスタンスタイプ。
Type: String
OOSAssumeRole:
Default: OOSServiceRole
Description: タスクを実行するために OOS がこのロールを引き受けます。
Type: String
SecurityGroupId:
Description: 新しいインスタンスのセキュリティグループ ID。
Type: String
VSwitchId:
Description: 新しいインスタンスの仮想スイッチ ID。
Type: String
RamRole: '{{OOSAssumeRole}}'
Tasks:
- Action: ACS::ExecuteAPI
Description: '指定されたパラメーターでインスタンスを実行します。'
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: test
Headers:
Content-Type: application/json
URI: https://oapi.dingtalk.com/robot/send?access_token=your_access_token
{
"FormatVersion": "OOS-2019-06-01",
"Outputs": {
"InstanceIds": {
"Type": "List",
"Value": " {{ runInstances.InstanceIds }} "
}
},
"Parameters": {
"ImageId": {
"Description": "新しいインスタンスのイメージ ID。",
"Type": "String"
},
"InstanceType": {
"Description": "新しいインスタンスのインスタンスタイプ。",
"Type": "String"
},
"SecurityGroupId": {
"Description": "新しいインスタンスのセキュリティグループ ID。",
"Type": "String"
},
"VSwitchId": {
"Description": "新しいインスタンスの仮想スイッチ ID。",
"Type": "String"
},
"OOSAssumeRole": {
"Type": "String",
"Description": "タスクを実行するために OOS がこのロールを引き受けます",
"Default": "OOSServiceRole"
}
},
"RamRole": "{{OOSAssumeRole}}",
"Tasks": [
{
"Action": "ACS::ExecuteAPI",
"Description": "指定されたパラメーターでインスタンスを実行します。",
"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"
}
}
}
}
}
]
}