全部產品
Search
文件中心

CloudOps Orchestration Service:ACS-MNS-PublishMessage

更新時間:Sep 06, 2024

模板名稱

ACS-MNS-PublishMessage 發布訊息至MNS主題

立即執行

模板描述

向指定的MNS主題發布訊息,訊息發布到主題後隨即會被推送給Endpoint消費

模板類型

自動化

所有者

Alibaba Cloud

輸入參數

參數名稱

描述

類型

是否必填

預設值

約束

topicName

主題名稱

String

message

MNS推送的訊息

String

regionId

地區ID

String

{{ ACS::RegionId }}

messageType

MNS推送訊息的類型

String

default

messageAttributes

推送訊息的屬性

Json

{}

OOSAssumeRole

OOS扮演的RAM角色

String

""

輸出參數

參數名稱

描述

類型

message

Json

執行此模板需要的權限原則

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "mns:PublishMessage"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

詳情

ACS-MNS-PublishMessage詳情

模板內容

FormatVersion: OOS-2019-06-01
Description:
  en: Publish a message to the specified MNS topic. After the message is published to the topic, it will be pushed to Endpoint for consumption
  zh-cn: 向指定的MNS主題發布訊息,訊息發布到主題後隨即會被推送給Endpoint消費
  name-en: ACS-MNS-PublishMessage
  name-zh-cn: 發布訊息至MNS主題
  categories:
    - security
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId
      zh-cn: 地區ID
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  topicName:
    Label:
      en: TopicName
      zh-cn: 主題名稱
    Type: String
  message:
    Label:
      en: Message
      zh-cn: MNS推送的訊息
    Type: String
  messageType:
    Label:
      en: MessageType
      zh-cn: MNS推送訊息的類型
    Description:
      en: (defalut:to publish a message to the subject of MNS, SMS:to push the message to smsendpoint, mail:to push the message to mailendpoint)
      zh-cn: (defalut:為向mns的主題發布訊息,sms:訊息推送到SmsEndpoint,mail:訊息推送到MailEndpoint)
    Type: String
    Default: default
    AllowedValues:
      - default
      - sms
      - mail
  messageAttributes:
    Label:
      en: MessageAttributes
      zh-cn: 推送訊息的屬性
    Description:
      en: 'Required when message type is SMS and mail (the content of mail and ssm are different, please refer to the document https://help.aliyun.com/document_detail/27497.html).'
      zh-cn: '當messageType為sms與mail時為必填項(mail與ssm的內容不同請參考文檔https://help.aliyun.com/document_detail/27497.html)。'
    Type: Json
    Default: {}
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
      zh-cn: OOS扮演的RAM角色
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: publishMessage
    When:
      'Fn::Equals':
        - '{{ messageType }}'
        - default
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Publish a message to the specified topic
      zh-cn: 向指定的主題發布訊息
    Properties:
      Service: MNS
      API: PublishMessage
      Method: POST
      URI: '/topics/{{ topicName }}/messages'
      Headers: {}
      Parameters:
        RegionId: '{{ regionId }}'
        AccountId: '{{ ACS::AccountId }}'
      Body: '<?xml version="1.0" encoding="utf-8"?><Message xmlns="http://mns.aliyuncs.com/doc/v1/"><MessageBody>{{ message }}</MessageBody></Message>'
    Outputs:
      message:
        Type: Json
        ValueSelector: .
  - Name: publishSmsMessage
    When:
      'Fn::Equals':
        - '{{ messageType }}'
        - sms
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Publish a message to the specified topic abourt sms, and push it to sms endpoint
      zh-cn: 向指定的主題發布相關訊息,並推送給簡訊
    Properties:
      Service: MNS
      API: PublishMessage
      Method: POST
      URI: '/topics/{{ topicName }}/messages'
      Headers: {}
      Parameters:
        RegionId: '{{ regionId }}'
        AccountId: '{{ ACS::AccountId }}'
      Body: '<?xml version="1.0" encoding="utf-8"?><Message xmlns="http://mns.aliyuncs.com/doc/v1/"><MessageBody>{{ message }}</MessageBody><MessageAttributes><DirectSMS>{{ messageAttributes }}</DirectSMS></MessageAttributes></Message>'
    Outputs:
      message:
        Type: Json
        ValueSelector: .
  - Name: publishMailMessage
    When:
      'Fn::Equals':
        - '{{ messageType }}'
        - mail
    Action: 'ACS::ExecuteAPI'
    Description:
      en: Publish a message to the specified topic abourt mail, and push it to mail endpoint
      zh-cn: 向指定的主題發布郵箱相關的訊息,並推送給郵箱
    Properties:
      Service: MNS
      API: PublishMessage
      Method: POST
      URI: '/topics/{{ topicName }}/messages'
      Headers: {}
      Parameters:
        RegionId: '{{ regionId }}'
        AccountId: '{{ ACS::AccountId }}'
      Body: '<?xml version="1.0" encoding="utf-8"?><Message xmlns="http://mns.aliyuncs.com/doc/v1/"><MessageBody>{{ message }}</MessageBody><MessageAttributes><DirectMail>{{ messageAttributes }}</DirectMail></MessageAttributes></Message>'
    Outputs:
      message:
        Type: Json
        ValueSelector: .
Outputs:
  message:
    Type: Json
    Value:
      'Fn::If':
        - 'Fn::Equals':
            - default
            - '{{ messageType }}'
        - '{{ publishMessage.message }}'
        - 'Fn::If':
            - 'Fn::Equals':
                - ssm
                - '{{ messageType }}'
            - '{{ publishSmsMessage.message }}'
            - '{{ publishMailMessage.message }}'