Step Function 中失败任务的 DLQ
DLQ on Failed Task in Step Function
如果 step 函数中的任务失败,在尝试重试策略后,有没有办法将这些失败的任务放入某些 DLQ 或类似的东西中,以便有人可以稍后监视这些消息并在修复后重新驱动它们问题?
是的,您可以在重试后捕获错误并将其发送到 SQS。这是一个例子。
{
"StartAt": "GetMyRecords",
"States": {
"GetMyRecords": {
"Type": "Task",
"Resource": "<resource arn>",
"TimeoutSeconds": 80,
"Retry": [
{
"ErrorEquals": [
"CustomError"
],
"IntervalSeconds": 300,
"MaxAttempts": 10,
"BackoffRate": 1.1
}
],
"Catch": [
{
"ErrorEquals": [
"CustomError"
],
"Next": "SendToSQS",
"ResultPath": "$.error"
}
],
"End": true
},
"SendToSQS": {
"Type": "Task",
"Resource": "arn:aws:states:::sqs:sendMessage",
"Parameters": {
"QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/myQueue",
"MessageBody.$": "$.input.message",
"MessageAttributes": {
"MyAttribute1": {
"DataType": "String",
"StringValue": "Value of attribute 1"
},
"MyAttribute1": {
"DataType": "String",
"StringValue": "Value of attribute 2"
}
}
},
"End": true
}
}
}
如果 step 函数中的任务失败,在尝试重试策略后,有没有办法将这些失败的任务放入某些 DLQ 或类似的东西中,以便有人可以稍后监视这些消息并在修复后重新驱动它们问题?
是的,您可以在重试后捕获错误并将其发送到 SQS。这是一个例子。
{
"StartAt": "GetMyRecords",
"States": {
"GetMyRecords": {
"Type": "Task",
"Resource": "<resource arn>",
"TimeoutSeconds": 80,
"Retry": [
{
"ErrorEquals": [
"CustomError"
],
"IntervalSeconds": 300,
"MaxAttempts": 10,
"BackoffRate": 1.1
}
],
"Catch": [
{
"ErrorEquals": [
"CustomError"
],
"Next": "SendToSQS",
"ResultPath": "$.error"
}
],
"End": true
},
"SendToSQS": {
"Type": "Task",
"Resource": "arn:aws:states:::sqs:sendMessage",
"Parameters": {
"QueueUrl": "https://sqs.us-east-1.amazonaws.com/123456789012/myQueue",
"MessageBody.$": "$.input.message",
"MessageAttributes": {
"MyAttribute1": {
"DataType": "String",
"StringValue": "Value of attribute 1"
},
"MyAttribute1": {
"DataType": "String",
"StringValue": "Value of attribute 2"
}
}
},
"End": true
}
}
}