的解析器映射模板参考 EventBridge - Amazon AppSync
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

的解析器映射模板参考 EventBridge

与 EventBridge 数据源一起使用的Amazon AppSync 解析器映射模板允许您向 Amazon EventBridge 总线发送自定义事件。

请求映射模板

PutEvents请求映射模板允许您将多个自定义事件发送到 EventBridge事件总线。 映射文档具有以下结构:

{ "version" : "2018-05-29", "operation" : "PutEvents", "events" : [{}] }

以下是以下的请求映射模板示例 EventBridge:

{ "version": "2018-05-29", "operation": "PutEvents", "events": [{ "source": "com.mycompany.myapp", "detail": { "key1" : "value1", "key2" : "value2" }, "detailType": "myDetailType1" }, { "source": "com.mycompany.myapp", "detail": { "key3" : "value3", "key4" : "value4" }, "detailType": "myDetailType2", "resources" : ["Resource1", "Resource2"], "time" : "2023-01-01T00:30:00.000Z" } ] }

响应映射模板

如果PutEvents操作成功,则来自的响应将包含 EventBridge 在以下内容中$ctx.result

#if($ctx.error) $util.error($ctx.error.message, $ctx.error.type, $ctx.result) #end $util.toJson($ctx.result)

执行诸如InternalExceptions或之类的PutEvents操作时发生的错误Timeouts将出现在$ctx.error。有关常见错误 EventBridge的列表,请参阅EventBridge 常见错误参考资料

result将采用以下格式:

{ "Entries" [ { "ErrorCode" : String, "ErrorMessage" : String, "EventId" : String } ], "FailedEntry" : number }
  • 参赛作品

    摄取的事件会导致成功和失败。如果摄取成功,则条目EventID中有。否则,您可以使用ErrorCodeErrorMessage来识别条目存在的问题。

    对于每条记录,响应元素的索引与请求数组中的索引相同。

  • FailedEntryCount

    失败的条目数。此值以整数表示。

有关响应的更多信息PutEvents,请参阅PutEvents

示例响应 1

以下示例是一个包含两个成功事件的PutEvents操作:

{ "Entries" : [ { "EventId": "11710aed-b79e-4468-a20b-bb3c0c3b4860" }, { "EventId": "d804d26a-88db-4b66-9eaf-9a11c708ae82" } ], "FailedEntryCount" : 0 }

示例响应 2

以下示例是一个包含三个事件、两个成功和一个失败的PutEvents操作:

{ "Entries" : [ { "EventId": "11710aed-b79e-4468-a20b-bb3c0c3b4860" }, { "EventId": "d804d26a-88db-4b66-9eaf-9a11c708ae82" }, { "ErrorCode" : "SampleErrorCode", "ErrorMessage" : "Sample Error Message" } ], "FailedEntryCount" : 1 }

PutEvents field

  • Version

    version字段与所有请求映射模板相同,它定义了模板使用的版本。此字段为必填。该值2018-05-29是 EventBridge 映射模板支持的唯一版本。

  • 操作

    唯一支持的操作是PutEvents。此操作允许您将自定义事件添加到事件总线。

  • 事件

    一系列将添加到事件总线的事件。此数组应分配 1-10 个项目。

    Event对象是有效的 JSON 对象,具有以下字段:

    • "source":定义事件源的字符串。

    • "detail":可用于附加关于事件信息的 JSON 对象。此字段可以是空地图 ({ })。

    • "detailType:标识事件类型的字符串。

    • "resources":标识事件中涉及的资源的 JSON 数组。此字段可以是空数组。

    • "time":以字符串形式提供的事件时间戳。这应该遵循 RFC3339 时间戳格式。

以下片段是有效Event对象的一些示例:

示例 1

{ "source" : "source1", "detail" : { "key1" : [1,2,3,4], "key2" : "strval" }, "detailType" : "sampleDetailType", "resources" : ["Resouce1", "Resource2"], "time" : "2022-01-10T05:00:10Z" }

示例 2

{ "source" : "source1", "detail" : {}, "detailType" : "sampleDetailType" }

示例 3

{ "source" : "source1", "detail" : { "key1" : 1200 }, "detailType" : "sampleDetailType", "resources" : [] }