EventBridge(CloudWatch 事件)用于 Step Functions 执行状态更改 - Amazon Step Functions
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 Amazon Web Services 服务入门

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

EventBridge(CloudWatch 事件)用于 Step Functions 执行状态更改

Amazon EventBridge 是一个Amazon服务中的状态更改,可用于响应Amazon资源的费用。您可以使用Amazon Step Functions使用 EventBridge 的标准工作流程,而快速工作流不会向 EventBridge 发出事件。将 Step Functions 标准工作流与 EventBridge 结合使用,可通过两种方式使用。

您可以配置 Step Functions tBridge 事件,以在执行状态更改时发出 EventBridge 事件。这使您能够监控您的工作流,而不必持续不断地使用 DescribeExecution API 进行轮询。根据状态机执行中的更改,您可以使用 EventBridge 目标来启动新的状态机执行,调用Amazon Lambda功能、将消息发布到 Amazon Simple Notification Service (Amazon SNS) 主题,等等。

您也可以在 EventBridge 中配置 Step Functions 状态机作为目标。这使您能够触发 Step Functions 工作流的执行,以响应另一项事件Amazon服务。

有关更多信息,请参阅 Amazon EventBridge 用户指南

EventBridge 负载

EventBridge 事件的定义中可以包含输入属性。对于某些事件,EventBridge 事件也可以在其定义中包含输出属性。

  • 如果发送到 EventBridge 的转义输入和转义输出组合超过 248KB,则输入将被排除。同样,如果转义输出超过 248KB,则输出将被排除。这是 EventBridge 事件配额的结果。

  • 您可以确定有效载荷是否已使用inputDetailsoutputDetails属性。有关更多信息,请参阅 。CloudWatchEventsExecutionDataDetails数据类型

  • 对于标准工作流,您可以通过使用DescribeExecution

  • DescribeExecution不适用于 “快速工作流”。如果您想查看完整的输入/输出,您可以使用标准工作流程包装快速工作流程。另一个选择是使用 Amazon S3 ARN。有关使用 ARN 的信息,请参阅使用 Amazon S3 ARN,而不是传递大型有效负载

Step Functions 事件示例

以下是向 EventBridge 发送事件的 Step Functions 示例:

在每种情况下,事件数据中的 detail 部分都提供与 DescribeExecution API 相同的信息。status 字段指明发送事件时执行的状态,根据发送的事件,状态可以是:RUNNINGSUCCEEDEDFAILEDTIMED_OUTABORTED

执行已启动

{ "version": "0", "id": "315c1398-40ff-a850-213b-158f73e60175", "detail-type": "Step Functions Execution Status Change", "source": "aws.states", "account": "012345678912", "time": "2019-02-26T19:42:21Z", "region": "us-east-1", "resources": [ "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name" ], "detail": { "executionArn": "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name", "stateMachineArn": "arn:aws:states:us-east-1:012345678912:stateMachine:state-machine", "name": "execution-name", "status": "RUNNING", "startDate": 1551225271984, "stopDate": null, "input": "{}", "inputDetails": { "included": true }, "output": null, "outputDetails": null } }

执行已成功

{ "version": "0", "id": "315c1398-40ff-a850-213b-158f73e60175", "detail-type": "Step Functions Execution Status Change", "source": "aws.states", "account": "012345678912", "time": "2019-02-26T19:42:21Z", "region": "us-east-1", "resources": [ "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name" ], "detail": { "executionArn": "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name", "stateMachineArn": "arn:aws:states:us-east-1:012345678912:stateMachine:state-machine", "name": "execution-name", "status": "SUCCEEDED", "startDate": 1547148840101, "stopDate": 1547148840122, "input": "{}", "inputDetails": { "included": true }, "output": "\"Hello World!\"", "outputDetails": { "included": true } } }

执行已失败

{ "version": "0", "id": "315c1398-40ff-a850-213b-158f73e60175", "detail-type": "Step Functions Execution Status Change", "source": "aws.states", "account": "012345678912", "time": "2019-02-26T19:42:21Z", "region": "us-east-1", "resources": [ "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name" ], "detail": { "executionArn": "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name", "stateMachineArn": "arn:aws:states:us-east-1:012345678912:stateMachine:state-machine", "name": "execution-name", "status": "FAILED", "startDate": 1551225146847, "stopDate": 1551225151881, "input": "{}", "inputDetails": { "included": true }, "output": null, "outputDetails": null } }

执行超时

{ "version": "0", "id": "315c1398-40ff-a850-213b-158f73e60175", "detail-type": "Step Functions Execution Status Change", "source": "aws.states", "account": "012345678912", "time": "2019-02-26T19:42:21Z", "region": "us-east-1", "resources": [ "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name" ], "detail": { "executionArn": "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name", "stateMachineArn": "arn:aws:states:us-east-1:012345678912:stateMachine:state-machine", "name": "execution-name", "status": "TIMED_OUT", "startDate": 1551224926156, "stopDate": 1551224927157, "input": "{}", "inputDetails": { "included": true }, "output": null, "outputDetails": null } }

执行已中止

{ "version": "0", "id": "315c1398-40ff-a850-213b-158f73e60175", "detail-type": "Step Functions Execution Status Change", "source": "aws.states", "account": "012345678912", "time": "2019-02-26T19:42:21Z", "region": "us-east-1", "resources": [ "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name" ], "detail": { "executionArn": "arn:aws:states:us-east-1:012345678912:execution:state-machine-name:execution-name", "stateMachineArn": "arn:aws:states:us-east-1:012345678912:stateMachine:state-machine", "name": "execution-name", "status": "ABORTED", "startDate": 1551225014968, "stopDate": 1551225017576, "input": "{}", "inputDetails": { "included": true }, "output": null, "outputDetails": null } }

将 Step Functions 事件路由到 EventBridge 控制台中的 EventBridge

  1. 在存储库的详细信息页面中,选择操作创建 EventBridge(CloudWatch 事件)事件规则

    
            创建 EventBridge 事件规则

    或者,打开 EventBridge 控制台,https://console.aws.amazon.com/events/。在导航窗格中,依次选择 EventsRules

  2. 选择 Create rule

  3. Event Source (事件源) 下,确保选中 Event Pattern (事件模式)

  4. 对于 Service Name (服务名称),选择 Step Functions

  5. 对于 Event Type (事件类型),选择 Step Functions Execution Status Change (Step Functions 执行状态更改)

  6. (可选)配置特定的状态、状态机 Amazon Simple Notification (ARN) 或执行 ARN。

  7. Targets (目标) 下,选择 Add target (添加目标),然后从列表中选择一个目标。例如,您可以启动 Lambda 函数,或者启动 Step Functions 状态机的执行。

  8. 添加特定目标的详细信息。

  9. 选择 Configure details。在 Configure rule details (配置规则详细信息) 页面上,输入Name (名称)Description (说明)

  10. 选择 Create rule