All Products
Search
Document Center

CloudOps Orchestration Service:ACS-MNS-PublishMessage

Last Updated:Jan 16, 2025

Template name

ACS-MNS-PublishMessage

Execute Now

Template description

Publishes a message to a specified Simple Message Queue (formerly MNS) topic. After the message is published to the topic, the topic pushes the message to the specified endpoints.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Data type

Required

Default value

Limit

topicName

The topic name.

String

Yes

message

The message that the Simple Message Queue (formerly MNS) topic pushes.

String

Yes

regionId

The region ID.

String

No

{{ ACS::RegionId }}

messageType

The type of the message that the Simple Message Queue (formerly MNS) topic pushes.

String

No

default

messageAttributes

The attributes of the pushed message.

Json

No

{}

OOSAssumeRole

The RAM role that is assumed by CloudOps Orchestration Service (OOS).

String

No

""

Output parameters

Parameter

Description

Data type

message

Json

Permission policy that is required to execute the template

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

References

ACS-MNS-PublishMessage

Template content

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  
  name-en: ACS-MNS-PublishMessage   
  categories:
    - security
Parameters:
  regionId:
    Type: String
    Label:
      en: RegionId     
    AssociationProperty: RegionId
    Default: '{{ ACS::RegionId }}'
  topicName:
    Label:
      en: TopicName      
    Type: String
  message:
    Label:
      en: Message       
    Type: String
  messageType:
    Label:
      en: MessageType       
    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)     
    Type: String
    Default: default
    AllowedValues:
      - default
      - sms
      - mail
  messageAttributes:
    Label:
      en: MessageAttributes       
    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).'
    Type: Json
    Default: {}
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole       
    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    
    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 
    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      
    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 }}'