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

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

EventBridge (CloudWatch Events),用于Step Functions 执行状态更改

亚马逊 EventBridge 是一个Amazon服务,可让您在响应状态更改Amazon资源。您可以使用Amazon Step Functions标准工作流程 EventBridge,而 Express 工作流不向发出事件 EventBridge. 可通过两种方式将SteStep Functions s 标准工作流与结合使用 EventBridge.

您可以配置 EventBridge 对在 Step Functions 状态机的执行状态发生变化时发出的事件做出反应的规则。这使您能够监控您的工作流,而不必持续不断地使用 DescribeExecution API 进行轮询。根据状态机执行的更改,您可以使用 EventBridge target 启动新的状态机执行,调用Amazon Lambda函数、向Amazon SSimple Notification Service (Amazon SNS) Simple Notification

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

有关更多信息,请参阅 。亚马逊 EventBridge 用户指南.

EventBridge 有效载荷

网络 ACL 和安全组都允许 (因此可到达您的实例) 的发起 ping 的 EventBridge 事件的定义中可以包含输入属性。对于某些事件, EventBridge事件的定义中也可以包含输出属性。

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

  • 您可以确定有效负载是否已被截断inputDetailsoutputDetails属性。有关更多信息,请参阅 。CloudWatchEventsExecutionDataDetails数据类型.

  • 对于标准工作流,您可以使用查看完整的输入和输出DescribeExecution.

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

Step Functions

以下是Step Functions 将事件发送到 EventBridge:

在每种情况下,事件数据中的 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 控制台

使用以下说明了解如何在特定 Step Functions 状态机成功完成运行时触发 Step Functions 状态机的执行。你使用亚马逊 EventBridge 控制台指定要触发执行的状态机。

  1. 在存储库的详细信息状态机的页面,选择操作,然后选择Create EventBridge (CloudWatch Events) 规则.

    
            Create EventBridge 事件规则

    或者,打开 EventBridge 控制台在https://console.aws.amazon.com/events/. 在导航窗格中,选择Rule事件.

  2. 请选择 Create rule (创建规则)

  3. 输入名称为你的规则(例如,StepFunctionsEventRule),然后可以选择输入说明对于规则。

  4. 适用于事件总线Rule type,请保留默认选项。

  5. 选择 Next(下一步)。

  6. UNDER事件源,请保留默认选项Amazon事件或 EventBridge 合作伙伴事件.

  7. UNDER事件模式中,执行以下操作:

    1. 事件源下拉列表中,保留默认选项Amazon服务.

    2. Amazon服务下拉列表中,选择Step Functions.

    3. 事件类型下拉列表中,选择Step Functions tions 执行状态更改.

    4. (可选)配置特定的状态、状态机 Amazon 资源名称 (ARN) 或执行 ARN。对于此过程,请选择特定状态,然后选择成功了从下拉列表中。

  8. 选择 Next(下一步)。

  9. 在存储库的选择目标页面上,保留默认选项Amazon服务.

  10. 选择一个目标下拉列表中,选择Amazon服务。例如,您可以启动 Lambda 函数,或者运行 Step Functions 状态机。对于此过程,请选择Step Functions.

  11. 状态机下拉列表中,选择状态机。

  12. UNDER执行角色,请保留默认选项为这个特定的资源创建一个新角色.

  13. 选择下一步,然后选择下一步

  14. 在存储库的审核和创建页面上,查看规则详细信息并选择创建规则.

    此时将创建规则并且Rule此时将显示页面,其中列出您的所有Amazon EventBridge 规则。