DEV Community

Daniel Van Houten
Daniel Van Houten

Posted on Originally published at tarmac.vantixsoftware.com

How to Redrive One Specific Message from an SQS DLQ

You just deployed the fix for a bug that dumped 8,000 failed jobs into your SQS dead-letter queue. Before you open the floodgates on all 8,000, you want to replay one specific order to verify the fix actually works in production.

Hit AWS's built-in Start DLQ redrive button and you will immediately find the problem: StartMessageMoveTask has no message-ID filter and no body filter. Setting its max rate to 1 message per second controls the speed, not a limit of one message.

To replay a single DLQ message safely, you have to do three separate calls: receive it, send a copy to the destination queue, and delete the original only after the send succeeds. Because those are not one atomic move, your consumer still needs to handle duplicates safely.

Step 1: Receive a small batch from the DLQ

SQS cannot look up a message by ID. Pull a small batch with a 5-minute visibility timeout (300 seconds) so you have time to inspect and verify the payload before the receipt handle expires:

DLQ_URL="https://sqs.us-east-1.amazonaws.com/123456789012/orders-dlq"
DESTINATION_URL="https://sqs.us-east-1.amazonaws.com/123456789012/orders"

aws sqs receive-message \
  --queue-url "$DLQ_URL" \
  --max-number-of-messages 10 \
  --wait-time-seconds 20 \
  --visibility-timeout 300 \
  --message-attribute-names All \
  --message-system-attribute-names All \
  --output json > dlq-batch.json

jq '.Messages[]? | {MessageId, Body, MessageAttributes}' dlq-batch.json
Enter fullscreen mode Exit fullscreen mode

Check the body to confirm the right order or business ID, then copy the MessageId from this batch (not from an old producer log—the DLQ message ID is what you received here). If your target isn't in the first 10 messages, see How to Search an SQS Queue.

Step 2: Build a send payload for that exact message

This jq command works on standard queues (with AWS CLI v2 and jq). It fails loudly if your TARGET_ID matches zero or multiple messages, so you don't accidentally send the wrong payload:

TARGET_ID="paste-the-message-id-from-this-batch"

jq -e --arg id "$TARGET_ID" --arg destination "$DESTINATION_URL" '
  [.Messages[]? | select(.MessageId == $id)]
  | if length == 1 then .[0] else error("Expected exactly one matching message") end
  | {
      QueueUrl: $destination,
      MessageBody: .Body,
      MessageAttributes: (.MessageAttributes // {})
    }
' dlq-batch.json > retry-request.json
Enter fullscreen mode Exit fullscreen mode

This preserves the message body and custom MessageAttributes without copying SQS system metadata like the old receive count.

Step 3: Send the copy first, then delete the original

Glance at retry-request.json first. Then run the send, and delete the original from the DLQ only if send-message exits cleanly:

if aws sqs send-message \
  --cli-input-json file://retry-request.json \
  --cli-binary-format base64 \
  --output json > retry-result.json; then
  RECEIPT_HANDLE=$(jq -er --arg id "$TARGET_ID" '
    [.Messages[]? | select(.MessageId == $id)]
    | if length == 1 then .[0].ReceiptHandle
      else error("Expected exactly one matching message") end
  ' dlq-batch.json) &&
  aws sqs delete-message \
    --queue-url "$DLQ_URL" \
    --receipt-handle "$RECEIPT_HANDLE"
fi
Enter fullscreen mode Exit fullscreen mode

Two quick edge cases to watch:

  • If the send succeeds but the delete fails, you now have a copy in both queues. Fix the delete—don't re-run the send blindly.
  • If your 5-minute receipt handle expires before you delete, receive the original again to get a fresh handle. Calling delete-message with an old handle can report success without actually removing it.

Every other message from your batch becomes visible on the DLQ again when the 5 minutes are up. Check your consumer logs to confirm the job actually succeeded—send-message only confirms SQS accepted the copy.

Quick heads-up for FIFO queues

Don't run the standard-queue JSON above unchanged on a FIFO destination:

  • You must include the original MessageGroupId.
  • Pass a fresh, explicit MessageDeduplicationId for this retry (and reuse that same ID only if you retry the exact same send after a network timeout). On queues with content-based deduplication, omitting an explicit ID can cause SQS to silently drop the retry within the 5-minute deduplication window.
  • Replaying a message does not put it back in its original sequence position—check whether newer events already changed the underlying state.

Skipping the shell scripts with Tarmac

Doing this bash-and-jq dance under incident pressure is a big reason I built Tarmac (a native SQS desktop client for macOS and Windows).

You fetch DLQ messages once into a local cache, search them by full text or JSON fields, inspect the exact payload, and right-click -> Stage send back to the source queue (with Delete originals after successful send checked). Everything goes into a Staged batch so you can double-check that you are touching one message before clicking Publish Actions. Tarmac sends first, deletes only after AWS confirms, and carries FIFO group and dedup IDs.

Viewing and local search are free with no account required; staged mutations like selective redrive are part of Tarmac Pro. You can download Tarmac here or read the full DLQ redrive workflow.


Originally published in the Tarmac documentation.

Top comments (0)