CreateRule

Updated at:

Creates an event rule for a specified event bus. You must specify an event pattern and an event target for an event rule. An event rule matches events based on the event pattern.

URI

/openapi/createRule

Limits

A maximum of 10 event rules can be created for a single event bus.

Request parameters

ParameterTypeRequiredExampleDescription
EventBusNameStringYesdefaultThe name of the event bus.For more information, see Limits.
RuleNameStringYesMNSRuleThe name of the event rule.For more information, see Limits.
DescriptionStringNoFilter rule for Message ServiceThe description of the event rule.
StatusStringNoENABLEThe status of the event rule. Valid values:
  • ENABLE: The event rule is enabled. It is the default state of the event rule.
  • DISABLE: The event rule is disabled.
FilterPatternStringNo
{\"source\": [{\"prefix\": \"acs.\"}],\"type\": [{\"prefix\":\"oss:ObjectReplication\"}],\"subject\":[{\"prefix\":\"acs:oss:cn-hangzhou:123456789098****:my-movie-bucket/\", \"suffix\":\".txt\"}]}
The event pattern, in the JSON format. Valid values:
  • stringEqual pattern
  • stringExpression pattern

    Each field can have a maximum of five expressions in the map data structure.

TargetsList<Target>YesThe event target to which events are delivered.
IdStringYes1The custom ID of the event target.
TypeStringYesacs.mns.queueThe type of the event target.. For information about other types of event targets, see Event target parameters.
EndpointStringYesacs:mns:cn-hangzhou:123456789098****:queues/myqueueThe endpoint of the event target.
PushRetryStrategyStringYesBACKOFF_RETRYThe retry policy that is used to push the event. Valid values:
  • BACKOFF_RETRY: backoff retry. The request can be retried up to three times. The interval between two consecutive retries is a random value between 10 and 20 seconds.
  • EXPONENTIAL_DECAY_RETRY: exponential decay retry. The request can be retried up to 176 times. The interval between two consecutive retries exponentially increases to 512 seconds, and the total retry time is one day. The specific retry intervals are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 512, ..., and 512 seconds, including a maximum of one hundred and sixty-seven 512 seconds in total.
DeadLetterQueueStringNoThe dead-letter queue. Events that are not processed or whose maximum retries have been exceeded are written to the dead-letter queue. Valid values: Simple Message Queue (formerly MNS) and ApsaraMQ for RocketMQ.
ArnStringNo
acs:mns:cn-hangzhou:123456789098****:/queues/rule-deadletterqueue
or
acs:mq:cn-hangzhou:123456789098****:/instances/myinstance/topic/mytopic
The Alibaba Cloud Resource Name (ARN) of the dead-letter queue. Events that are not processed or whose maximum retries have been exceeded are written to the dead-letter queue. Valid values: Simple Message Queue (formerly MNS) and ApsaraMQ for RocketMQ.
ParamListList<Param>YesThe parameters that the event passes.
resourceKeyStringYesbodyThe resource key of the transformed event.For more information, see Event target parameters.
formStringYesTEMPLATEThe transformation method.For more information, see Event target parameters.
valueStringYes
{\"key\"=\"value\"}
The event value to be transformed.
templateStringNoThe value of ${key} is ${value}!The format of the template.

Response parameters

ParameterTypeExampleDescription
RuleARNStringacs:eventbridge:cn-hangzhou:123456789098****:eventbus/default/rule/MNSRuleThe ARN of the event rule. The ARN is used for authorization.

Examples

Sample requests

POST /openapi/createRule HTTP/1.1
Host: 123456789098****.eventbridge.cn-hangzhou.aliyuncs.com
Date: Sat, 18 Apr 2020 05:30:41 GMT
x-eventbridge-version: 2020-04-01
Authorization: acs vZ3VL0SuJdHi****:Jo2PbT******azYAYoYslKLvWzg=
Content-Type: application/json;charset=UTF-8
Content-Length: 26

{
    "EventBusName":"default",
    "RuleName":"MNSRule",
    "Description":"Filter rule for Message Service",
    "Status":"ENABLE",
    "filterPattern":"{\"source\": [{\"prefix\": \"acs.\"}],\"type\": [{\"prefix\":\"oss:ObjectReplication\"}],\"subject\":[{\"prefix\":\"acs:oss:cn-hangzhou:123456789098****:my-movie-bucket/\", \"suffix\":\".txt\"}]}",
    "Targets":[
        {
            "Id":"1",
            "Type":"acs.mns.queue",
            "Endpoint":"acs:mns:cn-hangzhou:123456789098****:queues/myqueue",
            "PushRetryStrategy":"BACKOFF_RETRY",
            "DeadLetterQueue":{
            "Arn":"acs:mns:cn-hangzhou:123456789098****:/queues/rule-deadletterqueue"
            },
            "ParamList":[
                {
                    "resourceKey":"queue",
                    "form":"CONSTANT",
                    "value":"myqueue"
                },
                {
                    "resourceKey":"body",
                    "form":"TEMPLATE",
                    "value":"{\"key\"=\"value\"}",
                    "template":"The value of ${key} is ${value}!"
                }
            ]
        }
    ]
}

Sample responses

HTTP/1.1 200 OK
Server: AliyunEventBridge
Connection: keep-alive
Content-Type: application/json;charset=utf-8
Content-Length: 79
x-eventbridge-request-id: 5E9A9081333245F1D800****
Date: Sat, 18 Apr 2020 05:30:41 GMT

{
    "RuleARN":"acs:eventbridge:cn-hangzhou:123456789098****:eventbus/default/rule/MNSRule"
}