Replay failed SQS messages when a bug fix is merged
When you merge a fix in GitHub, this agent checks the matching dead-letter queue, replays the failed messages, and reports back on the pull request and in Slack.
When a pull request is merged in GitHub, decide whether that merge is a bug fix worth replaying failed messages for, and if so redrive the matching Amazon SQS dead-letter queue automatically. Use a webhook trigger on merged pull requests.
Start by calling the GitHub Get a Pull Request action for the merged pull request and read its title, body, and labels. Only proceed when the pull request carries a redrive label (for example redrive or replay-dlq) or names a queue in its description on a line like "Redrive: orders-processing-dlq". If neither signal is present, stop silently: do not comment, do not post to Slack, and do not touch any queue.
When it does proceed, use the Amazon SQS Get Queue URL action to resolve the named dead-letter queue by name. Then call Get Queue Attributes to read the approximate number of messages, and stop if the queue is already empty. Call List Dead Letter Source Queues against that queue to confirm it really feeds the source queue the fix targets, and use the source queue it returns as the replay destination. Only SQS dead-letter queues can be used as a redrive source, so if the named queue turns out not to be a dead-letter queue for any source queue, stop and say so in Slack instead of starting a task.
Sample a handful of messages (up to 10) with the Receive Message action so you can summarise what was actually failing before touching anything. Read them only. Never call Delete Message, Delete Message Batch, or Purge Queue on the sampled messages, so the visibility timeout returns them to the queue and the replay stays complete.
Before starting any replay, apply two safety gates. Do not redrive when the dead-letter queue depth is above a configurable ceiling, defaulting to 5,000 messages. Do not redrive when the pull request is a revert, which you can detect from a title starting with "Revert" or a revert label. In either case, skip Start Message Move Task entirely and instead post the summary to Slack asking a person to confirm before the replay runs.
When both gates pass, call Start Message Move Task with the dead-letter queue as the source and the confirmed source queue as the destination, throttled with a messages-per-second cap (default 10) so the replay does not overwhelm the consumer. Start Message Move Task is asynchronous: it returns a TaskHandle rather than finishing inline. Follow up with List Message Move Tasks to read the current status and how many messages have moved so far.
Finally, post the replay receipt back on the merged pull request with the GitHub Create an Issue Comment action, and send the same summary to the engineering channel with the Slack Bot Send a Message action. Both should cover which queue was replayed, how many messages were in it, a plain-English read on the failure pattern from the sampled messages, and the move task status. Report the status you actually observed rather than claiming the replay has completed, since the task keeps running in the background after the workflow finishes.
Example output
What does this prompt do?
- Watches for merged pull requests and only acts when the pull request is tagged for a replay or names a queue to replay, so ordinary merges are ignored.
- Checks the dead-letter queue before touching it: confirms it is not empty, confirms it really feeds the queue your fix targets, and samples a few stuck messages to work out what was failing.
- Replays the backlog onto the live queue at a steady, capped rate so your consumers are not flooded.
- Posts a receipt on the merged pull request and in your engineering channel covering the queue, the number of messages, the failure pattern in plain English, and how the replay is progressing.
What do I need to use this?
- An AWS account with Amazon SQS queues, including a dead-letter queue attached to the queue you want to replay.
- A GitHub repository where your team merges fixes.
- A Slack workspace with a channel for engineering updates.
- A shared convention for marking a pull request as replay worthy, either a label or a line in the description naming the queue.
How can I customize it?
- Change the label or the description keyword that marks a pull request as worth replaying.
- Raise or lower the safety ceiling on queue size, 5,000 messages by default, above which the agent asks a human before replaying.
- Adjust how fast messages are replayed and pick which Slack channel gets the summary.
FAQs
Will this replay messages every time we merge something?
Does it delete the failed messages while it inspects them?
What happens if the queue has a huge backlog?
What if the merge was a revert rather than a fix?
Will it tell me when the replay has finished?
Related templates
When someone leaves, we check which shared passwords they used in their final months and post a ranked rotation list to your security channel.
Every Monday, check every S3 bucket for public exposure, missing encryption and weak backup settings, then get the risks ranked in Slack.
Twice every weekday, the conversations from your social inbox land on the right HubSpot contact timelines, with a Slack recap for sales.
Every morning, find the addresses that hard bounced or filed a spam complaint, update the matching HubSpot contacts, and post a short Slack recap.
Every weekday at 4pm, spot the threads that went quiet, stage a ready-to-send nudge in your mailbox, and get a ranked Slack recap.
When a HubSpot deal hits Closed Won, the customer's plan, seats and renewal dates land in your DynamoDB accounts table, with a Slack note showing what changed.
Stop replaying failed jobs by hand.
Ship the fix and let the replay, the safety checks, and the write up happen on their own.