SQS Messages Stuck in Flight? Find the Cause and Get Them Moving
Learn why AWS SQS messages stay in flight. Check visibility timeouts, failed deletes, FIFO message groups, and queue limits, then release a message safely.
Your queue has messages. Your worker says there is nothing to do. Somewhere, an order is waiting for a very patient customer.
An SQS message is in flight after a consumer receives it, while it is hidden and has not been deleted. That does not prove the consumer is still doing useful work. It might be processing, waiting on a slow service, or long gone.
Start with the counts. Then follow the worker that took the message.
1. Check what "stuck" means
In CloudWatch, compare these three SQS metrics:
| Metric | What it tells you |
|---|---|
ApproximateNumberOfMessagesVisible | Messages available to receive. |
ApproximateNumberOfMessagesNotVisible | Messages in flight. |
ApproximateNumberOfMessagesDelayed | Messages waiting for a delivery delay to end. |
These are estimates. Watch the trend over several minutes, not one point. Delayed messages are a different problem from messages a worker has already received. See the AWS CloudWatch metric definitions.
With the AWS CLI, read the queue counts and settings without receiving any messages. Replace the example URL with yours, and use credentials for that account and Region:
QUEUE_URL="https://sqs.us-east-1.amazonaws.com/123456789012/orders"
aws sqs get-queue-attributes \
--queue-url "$QUEUE_URL" \
--attribute-names \
ApproximateNumberOfMessages \
ApproximateNumberOfMessagesNotVisible \
ApproximateNumberOfMessagesDelayed \
VisibilityTimeout \
RedrivePolicyThe API calls the visible count ApproximateNumberOfMessages, without Visible at the end. VisibilityTimeout is the queue default. A receive request can use a different timeout. See GetQueueAttributes and ReceiveMessage.
2. Follow the receive, work, delete trail
Look for these three events in your worker logs: it received the message, it finished the job, and its delete succeeded. The missing event is your next clue.
| What you find | What to check next |
|---|---|
| Receive, then silence | A crash, a stuck request, or a worker waiting on another service. |
| Work finished, but no successful delete | Delete errors, missing permissions, or an old receipt handle. |
| Repeated visibility extensions | A timer may still be running after useful work stopped. |
| The same job appears again and again | The worker may be receiving it again as soon as each timeout ends. |
A successful job is not a successful delete. SQS does not read your "Done!" log line. Your consumer must delete the message, or use an integration that does this for it.
Every receive gives the message a new receipt handle. This is the token used to delete that received message. Use the latest handle, not the message ID. AWS warns that a delete with an old handle can report success without deleting the message. See DeleteMessage.
3. Check the visibility timer
If a worker crashes, its message normally becomes available when the visibility timeout ends. A long timeout makes that wait look like a fault. A worker that keeps extending the timeout can keep the message hidden longer.
The maximum visibility window is 12 hours from when the message was received. Extensions do not restart that limit. A steady in-flight count does not prove that one message has been held all that time. New messages and repeated receives can keep the count steady too. See AWS visibility timeout guidance.
Choose a timeout that covers normal processing. If work takes longer, extend it only while the worker is healthy and making progress.
Also check your debugging tools. Polling in the AWS console receives messages too. So does Tarmac: it holds the messages it fetches for its Visibility (min) setting, 15 minutes by default, and releases them when you quit. Your own inspection may explain the wait. See How to View SQS Messages Without Deleting Them.
4. For FIFO, check the message group
One slow message can make a FIFO group look like a traffic jam. While a received batch holds messages from a group, later receives cannot return more messages from that group until the held messages are deleted or visible again. Other groups can still move.
Check the MessageGroupId of the blocked work. If all jobs use the same group, they all share that wait. Do not change group IDs just to bypass it if your application needs that order. AWS explains this in FIFO queue delivery logic.
5. For Lambda, check the batch
When Lambda reads from SQS, each batch stays in flight for the queue's visibility timeout.
- An error holds the whole batch. If the function fails, every message in the batch stays hidden until the timeout ends, including the ones that succeeded. Then they all come back. To return only the failed messages, turn on
ReportBatchItemFailuresand report each failed message ID. - The timeout must cover the work. Set the queue's visibility timeout to at least six times the function timeout. If you use a batching window, add
MaximumBatchingWindowInSecondsto that.
See Lambda SQS error handling and Lambda SQS configuration.
6. Check the in-flight limit
For most standard queues, the limit is about 120,000 in-flight messages. Traffic and backlog can affect it. At the limit, short polling returns OverLimit. Long polling returns no new messages until the count drops, without that error.
If workers fetch faster than they finish, reduce how much they hold at once. Fix failed deletes. Add processing capacity if the workers are simply overloaded. See AWS standard queue quotas.
Can you view or delete messages in flight?
No. While a message is in flight, SQS does not return it to any receive request. No console, CLI, or other tool can read it until it becomes visible again.
To delete one message, you need its current receipt handle. Only the worker that received it has that handle.
PurgeQueue removes in-flight messages without a handle, but it deletes every message in the queue, visible and in flight. It can take up to 60 seconds, and you cannot undo it. Use it only on a queue you can empty, such as a test queue. See PurgeQueue.
Release one message you hold
If you have its current receipt handle, you can end the wait. First stop or coordinate with the worker that holds it. Releasing a message does not stop that worker's code.
RECEIPT_HANDLE="paste-the-current-receipt-handle-here"
aws sqs change-message-visibility \
--queue-url "$QUEUE_URL" \
--receipt-handle "$RECEIPT_HANDLE" \
--visibility-timeout 0This makes the message available for another receive. It does not delete it. The API needs a receipt handle; a message ID is not enough. Without the handle, let the visibility window end and check what receives it next. See ChangeMessageVisibility.
Check that the fix holds
Follow one business ID, such as an order ID, through a full processing attempt. Confirm the job completed and the delete succeeded. Then check that the queue trend improves.
If repeated failures sent the message to a dead-letter queue, fix the cause first. Then retry one specific DLQ message. One good retry tells you more than sending the whole backlog through the same broken code.
How to Filter SQS Messages So Each Consumer Gets Only Its Own
SQS cannot filter messages on receive. Route each kind of message to its own queue with SNS filter policies or EventBridge rules, or store job results where you can read them by ID.
How to Redrive One Specific Message from an SQS DLQ
Retry one AWS SQS dead-letter queue message without moving the whole DLQ. Select it locally, send a copy, then delete the original, with a CLI example and Tarmac steps.