Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DLQ on Failed Task in Step Function

In case of Failed Task in step function, after trying with retry strategy, is there a way I can put these Failed tasks in some DLQ or something like that so that someone can monitor these messages later and redrive them after fixing the issue?

like image 552
hatellla Avatar asked Mar 04 '23 18:03

hatellla


1 Answers

Yes you can catch the error after retry and send it to SQS. Here is an example.

{
   "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
      }
   }
}
like image 74
A.Khan Avatar answered Mar 27 '23 12:03

A.Khan