DLQ on Failed Task in Step Function

Viewed 3375

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?

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
      }
   }
}
Related