AWS步骤函数级超时,带有自定义错误处理,如Catch块



在AWS步骤函数中是否有一种方法可以使用TimeoutSeconds字段为整个函数定义超时,但在达到步骤函数级别超时时仍然采取自定义操作(触发lambda) ?

下面是一个函数定义示例,

{
"Comment": "An example of the Amazon States Language for fanning out AWS Batch job",
"StartAt": "Wait 60 secs",
"TimeoutSeconds": 10,
"States": {
"Wait 60 secs": {
"Type": "Task",
.
.
.
"End": true,
"Catch": [
{
"ErrorEquals": [
"States.All"
],
"Next": "Notify failure"
}
]
},
"Notify failure": {
"Type": "Task",
\ Push message to an sns topic
}
}
}

我想要一种方法来调用Notify failure步骤,当达到步长函数级超时时。

这可能最好通过使用AWS步骤函数工作流将向EventBridge发出的执行状态更改事件来处理。您可以编写规则来匹配以下事件,然后让EventBridge发送到您的SNS主题或调用Lambda函数。

{
"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
}
}

或者,您可以将其分解为两个状态机,其中一个状态机的核心逻辑(和超时)由您从"外部"调用。使用步进函数与自身集成的状态机(又名"嵌套")。并将补偿逻辑放在外部工作流中。

最新更新