All Products
Search
Document Center

EventBridge:CreateRule

Last Updated:Mar 15, 2024

Creates an event rule.

Operation description

You can call this API operation to create an event rule.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
eventbridge:CreateRuleWrite
  • Rule
    acs:eventbridge:{#regionId}:{#accountId}:eventbus/{#eventbusId}/rule/*
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
EventBusNamestringYes

The name of the event bus.

MyEventBus
DescriptionstringNo

The description of the event bus.

RuleNamestringYes

The name of the event rule.

MNSRule
StatusstringNo

The status of the event rule. Valid values: ENABLE: enables the event rule. It is the default status of the event rule. DISABLE: disables the event rule.

ENABLE
FilterPatternstringYes

The event pattern, in JSON format. Valid values: stringEqual and stringExpression. You can specify up to five expressions in the map data structure in each field.

You can specify up to five expressions in the map data structure in each field.

{\"source\": [{\"prefix\": \"acs.\"}],\"type\": [{\"prefix\":\"oss:ObjectReplication\"}],\"subject\":[{\"prefix\":\"acs:oss:cn-hangzhou:123456789098****:my-movie-bucket/\", \"suffix\":\".txt\"}]}
EventTargetsobject []No

The event targets.

IdstringYes

The ID of the custom event target.

12021
TypestringYes

The type of the event target. For more information, see Event target parameters.

acs.mns.queue
EndpointstringNo

The endpoint of the event target.

acs:mns:cn-hangzhou:123456789098****:queues/myqueue
PushRetryStrategystringNo

The retry policy that is used to push events. Valid values: BACKOFF_RETRY: backoff retry. If an event failed to be pushed, it 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. If an event failed to be pushed, it 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. The interval of 512 seconds is used for 167 retries.

BACKOFF_RETRY
DeadLetterQueueobjectNo

The dead-letter queue. Events that are not processed or whose maximum retries are exceeded are written to the dead-letter queue. The dead-letter queue feature is supported by the following queue types: Message Queue for Apache RocketMQ, Message Service (MNS), Message Queue for Apache Kafka, and EventBridge.

ArnstringNo

The Alibaba Cloud Resource Name (ARN) of the dead-letter queue. Events that are not processed or whose maximum retries are exceeded are written to the dead-letter queue. The ARN feature is supported by the following queue types: MNS and Message Queue for Apache RocketMQ.

acs:mns:cn-hangzhou:123456789098****:/queues/rule-deadletterqueue
ErrorsTolerancestringNo

The fault tolerance policy. Valid values: ALL: allows fault tolerance. If an error occurs, the event processing is not blocked. If the message fails to be sent after the maximum number of retries specified by the retry policy is reached, the message is delivered to the dead-letter queue or discarded based on your configurations. NONE: does not allow fault tolerance. If an error occurs and the message fails to be sent after the maximum number of retries specified by the retry policy is reached, the event processing is blocked.

ALL
ParamListobject []No

The parameters that are configured for the event target.

ResourceKeystringNo

The resource parameter of the event target. For more information, see Limits

body
FormstringNo

The format that is used by the event target parameter. For more information, see Limits.

TEMPLATE
ValuestringNo

The value of the event target parameter.

{\"key\"=\"value\"}
TemplatestringNo

The template that is used by the event target parameter.

The value of ${key} is ${value}!

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":"Filtering rule for MNS", "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}!" } ] } ] }

Response parameters

ParameterTypeDescriptionExample
object
Messagestring

The returned error message.

Remote error. requestId: [xxxx], error code: [xxx], message: [The target in event rule is invalid! Endpoint is xxx
RequestIdstring

The request ID.

1AD6D598-7506-5D2C-81EA-30E3241A903A
Dataobject

The returned data.

RuleARNstring

The ARN of the event rule. The ARN is used for authorization.

acs:eventbridge:cn-hangzhou:123456789098****:eventbus/default/rule/MNSRule
Codestring

The returned HTTP status code. The HTTP status code 200 indicates that the request is successful.

200
Successboolean

Indicates whether the request is successful. Valid values: true and false.

true

Examples

Sample success responses

JSONformat

{
  "Message": "Remote error. requestId: [xxxx], error code: [xxx], message: [The target in event rule is invalid! Endpoint is xxx",
  "RequestId": "1AD6D598-7506-5D2C-81EA-30E3241A903A",
  "Data": {
    "RuleARN": "acs:eventbridge:cn-hangzhou:123456789098****:eventbus/default/rule/MNSRule"
  },
  "Code": "200",
  "Success": true
}

Error codes

HTTP status codeError codeError message
403ServiceNotEnableService not enable

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
No change history