DEV Community

Daniel Van Houten
Daniel Van Houten

Posted on Edited on Originally published at tarmac.vantixsoftware.com

How to View SQS Messages Without Deleting Them

Whenever something goes sideways in an SQS-backed system, the first instinct is always: "Let me just look at a couple of messages to see what the payload looks like."

Good news first: viewing an SQS message does not delete it. SQS only removes a message when someone explicitly calls DeleteMessage with its receipt handle, or when it ages past the queue's retention period.

The catch is that SQS has no true read-only peek. To read a message, you have to receive it—and receiving changes queue state in three ways that are easy to forget during an incident.

What happens when you "just look"

  1. Real consumers have to wait. While you hold the message, it is invisible for the visibility timeout. Workers and Lambda triggers cannot touch it until the timer expires or you release it.
  2. You bump ApproximateReceiveCount. SQS treats every receive without a delete as a failed attempt. Peek at the same message a few times on a queue with a low maxReceiveCount, and you can accidentally shove a healthy message straight into the dead-letter queue.
  3. FIFO message groups pause. Holding one message on a FIFO queue blocks every other message in that same MessageGroupId until you let it go.

The safe habit is simple: use a short visibility timeout, watch the receive count, and release the messages back to the queue as soon as you grab the payload.

Option 1: The AWS Console

  1. Open your queue in the SQS Console.
  2. Click Send and receive messages.
  3. Click Poll for messages and open a message to inspect its body and attributes.

As long as you do not click Delete, the messages stay on the queue and become visible again when the queue's default visibility timeout runs out. The list also shows each message's receive count so you know if you are getting close to the DLQ threshold.

Option 2: AWS CLI + jq (with an immediate release)

If you want tighter control—and don't want messages sitting hidden for a long queue default timeout—receive up to 10 messages with a 60-second visibility timeout and save them locally:

QUEUE_URL="https://sqs.us-east-1.amazonaws.com/123456789012/orders"

aws sqs receive-message \
  --queue-url "$QUEUE_URL" \
  --max-number-of-messages 10 \
  --visibility-timeout 60 \
  --message-system-attribute-names ApproximateReceiveCount SentTimestamp \
  --message-attribute-names All \
  --output json > peek.json
Enter fullscreen mode Exit fullscreen mode

Inspect the payloads locally:

jq '.Messages[]? | {MessageId, ReceiveCount: .Attributes.ApproximateReceiveCount, Body}' peek.json
Enter fullscreen mode Exit fullscreen mode

Then release them right away so your real consumers do not wait out the 60 seconds:

jq -r '.Messages[]?.ReceiptHandle' peek.json |
  while read -r handle; do
    aws sqs change-message-visibility \
      --queue-url "$QUEUE_URL" \
      --receipt-handle "$handle" \
      --visibility-timeout 0
  done
Enter fullscreen mode Exit fullscreen mode

Keep in mind that one receive-message call returns at most 10 messages, and standard queues do not guarantee order. If you need to hunt through a deeper queue, see How to Search an SQS Queue for a Message.

Option 3: A desktop client that caches locally

I built Tarmac (macOS and Windows) mostly because I got tired of writing throwaway jq scripts every time I needed to inspect a queue without risking an accidental delete in the AWS Console.

In Tarmac Free, delete isn't even enabled—it only receives, inspects, and releases:

  1. Select a queue, set Count and Visibility (min), and click Fetch Messages.
  2. Click any message to read formatted JSON, message attributes, receive count, and timestamps.
  3. Everything you fetch stays in a local cache on your machine, so you can search and re-read payloads later without hitting SQS again. When you quit or clear the cache, Tarmac releases any messages it still holds.

If you just want to watch live traffic roll in, Live Tail grabs one message per tick with a 1-second visibility timeout and stops automatically if a message gets close to the queue's redrive limit. (Deletes and redrives are Pro features, and they are always staged for review before anything gets published.)


Originally published in the Tarmac documentation.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The second side effect is the one I would put in bold for anyone debugging in production: peeking at the same message a few times can push a healthy message into the DLQ when maxReceiveCount is low — so the "just looking" you do during an incident can quietly create a second incident. Your CLI pattern with the immediate change-message-visibility release is the right habit, and the 10-message cap per receive-message call is worth remembering when you are hunting one specific payload in a busy queue. One thing I would add: do you set the visibility timeout on the peek call itself, or rely on the queue default and release fast — and which one has burned you less when the release step itself fails?