背景信息
事件总线EventBridge支持的事件内容转换类型如下:
完整事件
当转化类型为完整事件时,事件总线EventBridge不对事件进行转换,将原生CloudEvents的完整结构路由到事件目标。下表介绍经过完整事件转换前后的事件示例。
转换前的事件 | 转换类型 | 转换后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.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
}
}
| 完整事件 | {
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.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
}
}
|
部分事件
当转换类型为部分事件时,事件总线EventBridge通过JSONPath从CloudEvents中提取事件中的参数,将指定的事件内容路由到事件目标。下表介绍经过部分事件转换前后的事件示例。
转换前的事件 | 转换类型 | 转换后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.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
}
}
| 部分事件 $.data.name
说明 部分事件只支持定义一个变量。 value不超过10240个字符。
| test
|
常量
当转换类型为常量时,事件只起到触发器的作用,不管事件内容是什么,事件总线EventBridge都把常量路由到事件目标。下表介绍经过常量转换前后的事件示例。
转换前的事件 | 转换类型 | 转换后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.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
}
}
| 常量 test1
| test1
|
模板
当转换类型为模板时,通过自定义模板、定义模板里需要的变量,事件总线EventBridge通过JSONPath从CloudEvents提取事件中的参数,把这些值存放在变量中,然后按照模板定义的格式路由到事件目标。下表介绍经过模板转换前后的事件示例。
转换前的事件 | 转换类型 | 转换后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.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
}
}
| 模板 变量 {
"name":"$.data.name",
"constant":"Please deal with it timely."
}
模板 The instance is broken,which name is ${name}, ${constant}
| The instance is broken,which name is test, Please deal with it timely.
|
您也可以创建String格式和JSON格式的模板,通过自定义模板将事件转换成示例输出,然后路由到事件目标。以下为事件总线EventBridge支持的模板类型:
表 1. 简单String
转换前的事件 | 转换类型 | 转换后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.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"
}
}
| 模板 | "name test is in RUNNING"
|
表 2. 简单JSON
转换前的事件 | 转换类型 | 转换后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.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"
}
}
| 模板 变量 {
"name":"$.data.name",
"state":"$.data.state"
}
模板 {
"name":"${name}",
"state":"${state}"
}
| {
"name":"test",
"state":"RUNNING"
}
|
表 3. 混合变量和常量的JSON
转换前的事件 | 转换类型 | 转换后的事件 |
{
"id":"7adc8c1a-645d-4476-bdef-5d6fb57f****",
"source":"acs.oss",
"specversion":"1.0",
"type":"oss:ObjectCreated:PostObject",
"datacontenttype":"application/json",
"dataschema":"http://example.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"
}
}
| 模板 变量 {
"name":"$.data.name",
"state":"$.data.state"
}
模板 {
"name":"${name}",
"state":[
9,
"${state}",
true
],
"Transformed":"Yes"
}
| {
"name":"test",
"state":[
9,
"RUNNING",
true
],
"Transformed":"Yes"
}
|
表 4. 嵌套JSON
转换前的事件 | 转换类型 | 转换后的事件 |
{
"id": "45ef4dewdwe1-7c35-447a-bd93-fab****",
"source": "acs.imm",
"specversion": "1.0",
"subject": "acs.imm:cn-hangzhou:123456789098****:215672",
"time": "2020-11-19T21:04:41+08:00",
"type": "imm:FileMeta:Index",
"aliyunaccountid": "123456789098****",
"aliyunpublishtime": "2020-11-19T21:04:42.179PRC",
"aliyuneventbusname": "default",
"aliyunregionid": "cn-hangzhou",
"aliyunpublishaddr": "172.25.XX.XX",
"data": {
"ProjectName": "test_project",
"DatasetName": "test_dataset",
"RequestId": "D2A3AE88-D17C-4CCC-B149-6651115C****",
"StartTime": "2021-07-22T14:03:15.489885+08:00",
"EndTime": "2021-07-22T14:05:15.489885+08:00",
"Message": "InvalidParameter",
"Success": false,
"Files": [
{
"URI": "oss://bucket/file",
"CustomId": "defaultId",
"CustomLabels": {
"Key1": "Val1",
"Key2": "Val2"
},
"Error": "InternalError"
}
]
}
}
| 模板 变量 {
"ProjectName":"$.data.ProjectName",
"Files":"$.data.Files"
}
模板 {
"ProjectName":"${ProjectName}",
"Files":${Files}
}
| {
"ProjectName":"test_project",
"Files": [
{
"URI": "oss://bucket/file",
"CustomId": "defaultId",
"CustomLabels": {
"Key1": "Val1",
"Key2": "Val2"
},
"Error": "InternalError"
}
]
}
|
在模板中支持2个处理特殊字符的函数分别是jsonEscape和htmlEscape。