I have an AWS SQS queue which receives the messages, iterates through them printing the details and then I attempt to delete them. Unfortunately they are not deleting even though I get a success response. I can't figure out why they are not being removed when I am sure I've used similar code before.
The basic example I'm trying is like this:
import boto3
# Create SQS client
sqs = boto3.client('sqs',
region_name='',
aws_access_key_id='',
aws_secret_access_key=''
)
queue_url = ''
# Receive message from SQS queue
response = sqs.receive_message(
QueueUrl=queue_url,
AttributeNames=[
'All'
],
MaxNumberOfMessages=10,
MessageAttributeNames=[
'All'
],
VisibilityTimeout=0,
WaitTimeSeconds=0
)
print(len(response['Messages']))
for index, message in enumerate(response['Messages']):
print("Index Number: ", index)
print(message)
receipt_handle = message['ReceiptHandle']
# do some function
sqs.delete_message(
QueueUrl=queue_url,
ReceiptHandle=receipt_handle
)
Probably because you are using VisibilityTimeout=0
. This means that the message immediately goes back to the SQS queue. So there is nothing to delete for you.