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

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

SteBridge (CloudWatch Events) 适用于 Step Functions 执行状态更改

Amazon EventBridge 是Amazon该服务使您能够响应Amazon资源。您可以使用Amazon Step Functions具有 EventBridge 的标准工作流程,而 Express 工作流程不会向 EventBridge 发送事件。可通过两种方式使用 Step Functions 标准工作流与 EventBridge。

您可以配置 Step Functions 以在执行状态更改时发出 EventBridge 事件。这使您能够监控您的工作流,而不必持续不断地使用 DescribeExecution API 进行轮询。根据状态机执行中的更改,您可以使用 EventBridge 目标来启动新的状态机执行,调用Amazon LambdaAmazon SNS 主题将消息发布到 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不适用于 Express 工作流程。如果你想看到完整的输入/输出,你可以用标准工作流程包装你的 Express 工作流程。另一个选择是使用 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 } }

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

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

    
            创建 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 资源名称 (ARN) 或执行 ARN。

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

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

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

  10. 选择 Create rule (创建规则)