Post

DLQ dump with Bun

Using sh() helper from the previous post we can make a script for dumping DLQ locally for inspecting failed events.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const queue_url = Bun.argv[2];
(
  await sh(`aws sqs receive-message`, {
    'queue-url': queue_url,
    'max-number-of-messages': 10,
  }).json()
).Messages.forEach(async (msg) => {
  await Bun.write(`messages/${msg.MessageId}.json`, JSON.stringify(msg, null, 2));

  await sh(`aws sqs delete-message`, {
    'queue-url': queue_url,
    'receipt-handle': msg.ReceiptHandle,
  });
})

It would be even nicer if one could do

1
await $`${obj} > obj.json`

but oh well.

Now we can log all messages with a simple loop:

1
2
3
for await (let path of $`ls messages/*.json`.lines()) {
  if (path) console.log(await Bun.file(path).json());
}
This post is licensed under CC BY 4.0 by the author.