SQS: why did the message come back?
Receive the same message twice and see what changes when you delete it.
Reading an SQS message does not delete it. See it happen with one queue, one message, and four steps.
Allow about five minutes for the exercise once the environment is ready.
Set up your environment
-
Clone the repository
If you already have the repository, run git pull from its root and enter this lab directory.
git clone https://github.com/leodc/devops-in-practice-labs.git cd devops-in-practice-labs/sqs-message-returns
Linux
-
Start the emulator
Install AWS Emulator 1.0.322 and Python with pip and venv. Then prepare the environment and start the emulator.
Install AWS Emulator 1.0.322 ↗python3 -m venv .venv .venv/bin/pip install -r requirements.txt aws-emulator --version bash start-emulator.sh- Leave this terminal running.
-
Open your working terminal
In a second terminal, enter the lab directory and activate its Python environment. Adjust the path to your clone.
cd devops-in-practice-labs/sqs-message-returns source .venv/bin/activate
Docker
-
Enter the lab environment
The container includes AWS Emulator 1.0.322 and Python. Logs stay in .lab on your computer.
bash docker-lab.sh- Use Bash and Docker with Linux containers; on Windows, run these commands in WSL.
Stage 1 / 4
Receive a message without deleting it
Create the queue, send hello-again, and receive it once.
python lab.py prepare
python lab.py receive Stop and inspect
- Find received_without_delete with receive_count 1 and save its message_id.
Has the message left the queue?
See explanation
ReceiveMessage hides it temporarily. The helper does not call DeleteMessage; in this exercise, the message becomes visible again after three seconds.
Stage 2 / 4
Receive the same message again
Run receive again. The command waits if the message is still hidden.
python lab.py receive Stop and inspect
- Compare message_id: it is unchanged. receive_count is now 2.
Did anyone have to send another message?
See explanation
No. The original message became available again because it was not deleted. That lets unfinished work be attempted again. Repeating this command increases the count further.
Reference logs
Your IDs and timestamps will differ.
{"body": "hello-again", "event": "received_without_delete", "message_id": "63b1c706-8395-4a85-aad5-fd0f644083c5", "receive_count": 1, "time": "2026-11-14T10:00:38.879509+00:00", "visibility_seconds": 3}
{"body": "hello-again", "event": "received_without_delete", "message_id": "63b1c706-8395-4a85-aad5-fd0f644083c5", "receive_count": 2, "time": "2026-11-14T10:00:42.174903+00:00", "visibility_seconds": 3} Stage 3 / 4
Delete it and check the result
Run ack to receive it with a fresh receipt handle and delete it immediately. Then check the queue.
python lab.py ack
python lab.py verify Stop and inspect
- Find received_for_delete for another receive, followed by deleted.
- Find verification with PASS, zero messages, and none in flight.
Why does ack receive it again before deleting?
See explanation
You may have paused between steps. A fresh receive gets a current receipt handle for DeleteMessage. Open ack in lab.py to see both API calls.
Reference logs
Your IDs and timestamps will differ.
{"counts": {"ApproximateNumberOfMessages": 0, "ApproximateNumberOfMessagesDelayed": 0, "ApproximateNumberOfMessagesNotVisible": 0}, "event": "verification", "messages_returned": 0, "result": "PASS", "time": "2026-11-14T10:00:46.541568+00:00"} Stage 4 / 4
Keep the sequence and finish
Delete the queue and read the full trace.
python lab.py cleanup
cat .lab/events.jsonl Stop and inspect
- Follow the same message_id from sent through deleted.
- Linux: stop terminal A with Ctrl+C. Docker: exit the shell. .lab/events.jsonl stays on your computer.
What was missing after receiving the message?
See explanation
Deleting it after completing the work. Receiving a message and acknowledging completion are separate operations. If you restarted the emulator before finishing, run python lab.py reset before prepare.
Receiving is not deleting
You observed the same message being delivered again and checked its deletion. That distinction also matters when a function processes messages for you.
References
Send it to someone who might find it useful.