EventBridge can transform event content. Specifically, EventBridge can transform events in the standard CloudEvents format to the event type that an event target can receive before the events are routed to the event target. This topic describes the transformation methods provided by EventBridge.

Background information

EventBridge supports the following transformation methods:

Complete event

If you select complete event as the transformation method, EventBridge does not transform the event and routes a complete event in the CloudEvents format to an event target. The following table describes examples of events before and after complete event transformation.
Note For more information about CloudEvents, visit CloudEvents 1.0.
Event before transformation Transformation method Event after transformation
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://taobao.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "aliyuneventbusname":"demo-bus",
    "aliyunregionid":"Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
Complete event
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://taobao.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "aliyuneventbusname":"demo-bus",
    "aliyunregionid":"Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}

Partial event

If you select partial event as the transformation method, EventBridge extracts fields from an event in the CloudEvents format by using JSONPath and routes the specified part of the event to an event target. The following table describes examples of events before and after partial event transformation.

Event before transformation Transformation method Event after transformation
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://taobao.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "aliyuneventbusname":"demo-bus",
    "aliyunregionid":"Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
Partial event
$.data.name
Note
  • Partial event transformation supports only one variable.
  • A value can be up to 1,024 characters in length.

test

Constant

If you select constant as the transformation method, EventBridge routes constants in an event to an event target regardless of what content the event contains. The following table describes examples of events before and after constant transformation.

Event before transformation Transformation method Event after transformation
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://taobao.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "aliyuneventbusname":"demo-bus",
    "aliyunregionid":"Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
Constant
test1
Note

A value can be up to 1,024 characters in length.

test1

Template

You can customize a template and define the variables in the template. If you select template as the transformation method, EventBridge extracts fields from an event in the CloudEvents format by using JSONPath, stores the values in variables, and then routes the event in the format that is defined in the template to an event target. The following table describes examples of events before and after template transformation.

Event before transformation Transformation method Event after transformation
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://taobao.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "aliyuneventbusname":"demo-bus",
    "aliyunregionid":"Shanghai",
    "data":{
        "name":"test",
        "scope":100
    }
}
Template
  • Variables
    {
        "name":"$.data.name",
        "constant":"Please deal with it timely."
    }
    Note
    • The values extracted by using JSONPath can be variables or constants.
    • A nested structure is not supported when you define variables.
    • A value can be up to 1,024 characters in length.

  • Template
    The instance is broken, which name is ${name}, ${constant}
    Note

    A template can contain up to 10,240 characters in length.

The instance is broken, which name is test, Please deal with it timely.

You can customize a template in the string or JSON format, transform an event based on the template, and route the event to an event target. EventBridge supports the following types of templates:

Table 1. Simple string
Event before transformation Transformation method Event after transformation
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://taobao.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "aliyuneventbusname":"demo-bus",
    "aliyunregionid":"Shanghai",
    "data":{
        "name":"test",
        "state":"RUNNING"
    }
}
Template
  • Variables
    {
        "name":"$.data.name",
        "state":"$.data.state"
    }
  • Template
    "name ${name} is in ${state}"
"name test is in RUNNING"
Table 2. Simple JSON
Event before transformation Transformation method Event after transformation
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://taobao.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "aliyuneventbusname":"demo-bus",
    "aliyunregionid":"Shanghai",
    "data":{
        "name":"test",
        "state":"RUNNING"
    }
}
Template
  • Variables
    {
        "name":"$.data.name",
        "state":"$.data.state"
    }
  • Template
    {
        "name":"${name}",
        "state":"${state}"
    }
{
    "name":"test",
    "state":"RUNNING"
}
Table 3. JSON that includes variables and constants
Event before transformation Transformation method Event after transformation
{
    "id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
    "source":"acs.oss",
    "specversion":"1.0",
    "type":"oss:ObjectCreated:PostObject",
    "datacontenttype":"application/json",
    "dataschema":"http://taobao.com/test.json",
    "subject":"acs:oss:cn-hangzhou:1234567:xls-papk/game_apk/123.jpg",
    "time":"2020-08-17T16:04:46.149Asia/Shanghai",
    "aliyuneventbusname":"demo-bus",
    "aliyunregionid":"Shanghai",
    "data":{
        "name":"test",
        "state":"RUNNING"
    }
}
Template
  • Variables
    {
        "name":"$.data.name",
        "state":"$.data.state"
    }
  • Template
    {
        "name":"${name}",
        "state":[
            9,
            "${state}",
            true
        ],
        "Transformed":"Yes"
    }
{
    "name":"test",
    "state":[
        9,
        "RUNNING",
        true
    ],
    "Transformed":"Yes"
}